Coroutine's Communication

DavidL Davidl at 126.com
Tue Apr 29 18:49:07 PDT 2008


Michel Fortin Wrote:

> 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/
> 

Yeah, I've stated that in this exact case we got the same effect as nestedfunc, but nested func loses the chance of overloading, so if you want different provider(nested func) behavior in the cunsumer(host func), you will have to include different providers in the cunsumer func. That bloats the consumer func. 



More information about the Digitalmars-d mailing list