[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Another example for syntactically lightweight closures
- From: pierre pracht <pierre.pracht@...>
- Date: Thu, 7 Feb 2008 09:00:21 +0100
Le 7 févr. 08 à 08:24, Asko Kauppi a écrit :
What would you think of a notation like this?
{
yyy= do =something end
xxx= do(a,b) =a+b end
zzz= do(a,b,c) if a then =b else =c end end
}
Haskell use :
yyy = something
xxx = \a b -> a+b
zzz = \a b c -> if a then b else c
"\" is read as "lambda".
May be more in line with lua syntax :
yyy = \=something end
www = \a= other a end
xxx = \(a,b)= a+b end
zzz = \(a,b,c) if a then =b else =c end end
Nearly the same as :
http://lua-users.org/wiki/RiscLua
Will make it a luaSub mod for trial, but thought of asking opinions
first.
do ... end -> function() ... end
do(...) ... end -> function(...) ... end
= exp -> return exp (within the enclosed block)
Especially the '=' trick is handy, since it makes simple closures
readable and does not (is this true?) overlap with existing valid
Lua syntax.
-asko
David Manura kirjoitti 7.2.2008 kello 4:30:
Miles Bader writes:
Bret Victor writes:
I thing I like about Lua syntax is that punctuation is kept
minimal,
and words are used (in, do, end) when that's how you would read the
code out loud.
I agree, in general -- I don't dislike punctuation heavy languages
like
C, but Lua has a consistent and attractive style of its own.
[Still, in
the middle of an expression, I think a punctuation-oriented lambda
syntax isn't out of place, even in Lua.]
In Lua, we do write "{1,2}" rather than "table 1, 2 end". Given
that functions
are fundamental data type, like tables, there is consistency in using
punctuation to denote functions, particularly when used as lambda
expressions.
Approaches for syntactically lightweight closures are also
discussed in [1].
[1] http://lua-users.org/wiki/ShortAnonymousFunctions