Coroutine's Communication

Michel Fortin michel.fortin at michelf.com
Tue Apr 29 05:30:27 PDT 2008


On 2008-04-29 00:33:40 -0400, davidl <davidl at 126.com> said:

> I suggest compiler accepts Function type arg as a scope referer.
> 
> Use case:
> 
> void func(int i)
> {
>     int j;
>     func1(get_current_scope, i);     	// which equivalent to j=i;
>     assert(j==i);
> }
> 
> void func1(func scope func_scope, ref int j)
> {
>      j = func_scope.j;
> }
> 
> The trick here is that routines are still routines, and you defaultly 
> get  their local vars consisting an object. Sometimes routines need to 
> access  some trivial

But can't you already do this in D with nested functions?

	void func(int i)
	{
		int j;
		void func1(ref int j1)
		{
			j = j1;
		}
		func1(i); // which is equivalent to j = i;
		assert(j == i);
	}

The scope of func is passed implicitly to func1 as a hidden pointer in 
the above call, and func1 can thus access any of func's variables.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list