Closures not yet supported in CTFE's

JS js.mdnq at gmail.com
Sat Jul 27 16:54:27 PDT 2013


On Saturday, 27 July 2013 at 17:18:29 UTC, H. S. Teoh wrote:
> On Sat, Jul 27, 2013 at 06:47:04PM +0200, JS wrote:
>> When I try to pass a lambda to a template, I get the subject 
>> error.
>> 
>> (string x) => { return x~"1"; }
>
> Drop the "=>", that syntax doesn't do what you think it does.
>
>
>> But when I jsut do
>> 
>> (string x) => x~"1"
>> 
>> it works....
>> 
>> Come on!!!
>
> Y'know, it would really help if you (1) show the full code 
> that's
> failing, and (2) calm down before posting to the forum.  I 
> understand
> that compiler bugs/limitations can be very aggravating, but 
> you're much
> more likely to get a helpful reply that way.
>
>

The code wouldn't help because that is not where the error is at. 
It is because I thought => was used for lambda's as it is in C#. 
I don't know why there is a special syntax for a direct return.

(string x) => { return x; } is trying to return a function that 
returns x using closure because of x is outside the inside 
function.

(string x) { return x; } is what I was trying to do. I knew that 
(string x) => ...; was simple notation for return ... but didn't 
think I was returning a function in any way.




More information about the Digitalmars-d-learn mailing list