Closures not yet supported in CTFE's
anonymous
anonymous at example.com
Sat Jul 27 19:50:17 PDT 2013
On Saturday, 27 July 2013 at 23:54:28 UTC, JS wrote:
> On Saturday, 27 July 2013 at 17:18:29 UTC, H. S. Teoh wrote:
[...]
>> Y'know, it would really help if you (1) show the full code
>> that's
>> failing,
[...]
>
> The code wouldn't help because that is not where the error is
> at.
It's not so much about providing the full source of your project,
but more about a reduced test case, a little snippet that
compiles (or should compile in your opinion). It lowers the
barrier for helpers quite a bit.
> It is because I thought => was used for lambda's as it is in C#.
I don't know C#. So I read a little MSDN[1] to find out what
(foo) => {bar}
means in C#. Apparently, it's a delegate that takes foo and does
bar. In D:
(foo) {bar}
However, D's "=>" syntax works the same as C#'s Expression
Lambdas.
> I don't know why there is a special syntax for a direct return.
Not sure, I'm understanding this right. You mean, why do we need
the arrow syntax when we can do the same thing with the braces
syntax?
Well, because it's shorter. C# does it too, doesn't it
(Expression Lambdas vs Statement Lambdas)? It's just that D has a
different syntax for Statement Lambdas than C#.
> (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.
I feel like you may have missed this: In D
(string x) => x
is equivalent to
(string x) { return x; }
[1] http://msdn.microsoft.com/en-US/library/vstudio/bb397687.aspx
More information about the Digitalmars-d-learn
mailing list