Problem about lambda expressions
Ali Çehreli
acehreli at yahoo.com
Tue Mar 27 10:09:52 PDT 2012
On 03/27/2012 06:42 AM, Tongzhou Li wrote:
> Hello again! I'm learning D, and I encountered a problem.
> I tried this code:
> http://ideone.com/hkpT6
> It works well. (Have no idea why codepad.org failed to compile it)
> I tried to write a lambda instead of function f, but I got nothing
printed.
The lambda syntax (=>) is only for when there is a single return
statement in the function literal:
http://dlang.org/expression.html#Lambda
As Kenji Hara has shown, you can have more than one expression in the
return statement by taking advantage of the comma operator but
personally I would use something else instead: the longer syntax, a
local function, etc.
Ali
More information about the Digitalmars-d-learn
mailing list