lua-users home
lua-l archive

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

On Thu, Nov 25, 2010 at 17:24, HyperHacker <> wrote:
> On Thu, Nov 25, 2010 at 15:17, Axel Kittenberger <> 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.

Looking at it again, in the second case the "end" isn't really
necessary since AFAIK nothing is allowed after "return" in a block
anyway. i.e. "return" could end a block just as "end" does. (Maybe
only in this context though lest it break things and confuse

Sent from my toaster.