lua-users home
lua-l archive

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


Sorry, Gmail flattens the threads, making it harder to distinguish
branches, and it's becoming late here. I should be more careful.

I was not talking about lazy evaluation, but, for example, the ability
to tie a callback to an event (key press, timer...), or to simulate
partial evaluation by having a function that returns a function that
returns a function... It is useful when writing DSLs.

This kind of code becomes harder to read than it should be when using
the current syntax.

I like the function statements (function foo() ... end), and the
current function expression syntax is fine for basic assignments, even
though the statement covers most of these cases too.

>  \x,y,z(return x*y+z)
>  \x,y,z(if x > 0 then return x*y+z else return 0 end)

I agree with you that a full "return" keyword make little sense in a
short function (except if you use it as a block, see Mark Hamburg's
post). That's why I'm advocating for two complementary syntaxes, with
a short return token, like, say

    collection:map |:x y z|x*y+z:|
    collection:map |:x y z: if x > 0 then |x*y+z else |0 end:|

compare with

    collection:map( function (x,y,z) if x > 0 then return x*y+z else
return 0 end end )

Simulating partial evaluation with this syntax:

    concat = |:a||:b||:c| print(a.." "..b.." "..c.."!") :|:|:|

    greeter = concat "Good"
    early_greeter = greeter "morning"
    late_greeter = greeter "evening"

    late_greeter "Doug" --> Good evening Doug!

-- Pierre-Yves