[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lightweight syntax: a dissident view
- From: Pierre-Yves Gérardy <pygy79@...>
- Date: Sat, 27 Nov 2010 01:31:43 +0100
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
- References:
- Re: Re: Re: Lightweight syntax: a dissident view, Gunnar Zötl
- Re: Re: Re: Lightweight syntax: a dissident view, Luis Carvalho
- Re: Re: Re: Lightweight syntax: a dissident view, Axel Kittenberger
- Re: Re: Re: Lightweight syntax: a dissident view, Pierre-Yves Gérardy
- Re: Re: Re: Lightweight syntax: a dissident view, Roberto Ierusalimschy
- Re: Re: Re: Lightweight syntax: a dissident view, Mateusz Czaplinski
- Re: Re: Re: Lightweight syntax: a dissident view, Axel Kittenberger
- Re: Lightweight syntax: a dissident view, Philippe Lhoste
- Re: Lightweight syntax: a dissident view, Pierre-Yves Gérardy
- Re: Lightweight syntax: a dissident view, Mark Hamburg
- Re: Lightweight syntax: a dissident view, Pierre-Yves Gérardy
- Re: Lightweight syntax: a dissident view, Pierre-Yves Gérardy
- Re: Lightweight syntax: a dissident view, Axel Kittenberger
- Re: Lightweight syntax: a dissident view, steve donovan
- Re: Lightweight syntax: a dissident view, phlnc8
- Re: Lightweight syntax: a dissident view, Doug Lua
- Re: Lightweight syntax: a dissident view, Pierre-Yves Gérardy
- Re: Lightweight syntax: a dissident view, Doug Lua