Immutable nested functions

Tomek Sowiński just at ask.me
Sat Jan 8 02:06:11 PST 2011


Robert Jacques napisał:

> >>  3. (vaguely related) Should there be means to express annotated  
> >> delegates in general (e.g. pure, nothrow).  
> >
> > There is.
> >   int delegate(int) pure square
> > 		= cast( int delegate(int z) pure )
> > 		(int z) { return z*z; };
> >  
> >> What about annotated lambdas?  
> >
> > See the line above -- at the moment it requires a cast. Yuck yuck yuck.
> > The other option would be for the compiler to automatically determine  
> > purity. I believe it always has access to the source code of the lambda,  
> > so there should be no problem to determine purity.  
> 
> Umm...  int delegate(int) pure square =  delegate(int z) pure { return  
> z*z; }; compiles and runs fine. What doesn't compile is (int z) pure {  
> return z*z; }; or anything similar.

Hm, you're right. Also, the argument list seems to be required with annotations:

int delegate() pure dg =  delegate pure { return 0; };  // error
int delegate() pure dg =  delegate() pure { return 0; };  // compiles

BTW, the syntax landscape seems densely populated, I wonder if demanded constructs like pure { } wouldn't confuse the parser in some corner-case.

It's all just syntax, though. I'm glad there's any way to get the job done.

-- 
Tomek



More information about the Digitalmars-d mailing list