lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Thu, Nov 25, 2010 at 15:17, Axel Kittenberger <axkibe@gmail.com> wrote:
>> Say myfunc() returns 3 values. Should they get truncated to 1 value by
>> the lambda? Parentheses around a function call will ordinarily
>> truncate it to one value - but that is confusingly at-odds with having
>> optional parentheses around lambda return values.
>>
>> Simplicity is not so easily achieved :)
>
> Ouch, you're right there, on both statements.
>
>

Why not simply "lambda(x) x == 2 end", then? I agree that most of
these suggestions are ugly and Perlish, and while there's nothing
wrong with Perl, Lua isn't Perl and thus shouldn't look like it,
especially only in certain cases like this.

Similar options:
f = fn(x,y) x+y --translates to: f = function(x,y) return x+y end
f = fn(x,y) do foo() return x+y end --translates to f = function(x,y)
foo() return x+y end
(that is, if a "do" follows the closing parenthesis, the "return" and
"end" are not added automatically, and the "do" is eaten.)

"fn" of course could be "lambda" or similar too but it seems like most
people here are trying to make it as short as possible.


-- 
Sent from my toaster.