Closures not yet supported in CTFE's
Meta
jared771 at gmail.com
Sat Jul 27 18:16:59 PDT 2013
On Saturday, 27 July 2013 at 23:54:28 UTC, JS wrote:
> 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.
It was a source of confusion for me at first as well, as I
expected `a => { ... }` to behave as it does in C#. That's not
the case, unfortunately, as { ... } is a delegate literal in D,
so you have to use the full `(a) { ... }` syntax. It's annoying,
but somewhat more bearable if you've worked with Javascript or
LUA before, since they have pretty much the same syntax for
function literals.
More information about the Digitalmars-d-learn
mailing list