"for" statement issue

ag0aep6g via Digitalmars-d digitalmars-d at puremagic.com
Sat Oct 22 10:11:26 PDT 2016


On 10/22/2016 05:53 PM, Nick Treleaven wrote:
> Probably (a, b => a + b) could be legal. Reasoning:
>
> 1. a could be an existing symbol in scope, otherwise it's an undefined
> identifier error.
> 2. If a was interpreted as an existing symbol which is followed by the
> comma operator, the expression (a) wouldn't have side effects so should
> be a compile error.

How is it guaranteed that `a` doesn't have side effects? May be a 
function call, since empty parentheses can be omitted in calls.

> 3. The bracketed comma expression would have to return the lambda b=>a+b
> as a value expression, which cannot compile because there are no
> arguments supplied for calling the lambda to obtain a value.

The lambda itself is a value, no?

----
int a() { import std.stdio; writeln("a"); return 1; }

void main()
{
     int delegate(int) dg = (a, b => a + b);
}
----


More information about the Digitalmars-d mailing list