lua-users home
lua-l archive

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


Fabien <fleutot+lua@gmail.com> writes:
> I've also experimented with shorted syntaxes for multiple statements instead
> of single expressions as aboved, but in the end I felt that it wasn't worth
> it. However, you can still use it (it's "do |foo, bar| stat1; stat2;...statn
> end"  in the currently available version IIRC), or define whatever suits
> you.

Hmm, since square-brackets are currently not valid in an
"expression-initial" context in lua, how about just using them as
syntactic sugar for an anonymous function?

This would allow using the classic smalltalk block syntax (blocks in
smalltalk are really lambda expressions):


   No-argument lambda expr:

      [ stmnt1; stmnt2; ...; expr ]

   is sugar for "function () stmnt2; stmnt2; ...; return expr; end"


   Lambda expr taking arguments:

      [ | arg1, arg2, ... | stmnt1; stmnt2; ...; expr ]

   is sugar for "function (arg1, arg2) stmnt2; stmnt2; ...; return expr; end"


While in general I like lua's "keywordy" syntax, I think it's awkward in
the middle of an expression, and a bracket syntax like [ ] makese more
sense in an expression context.


-Miles

-- 
"An atheist doesn't have to be someone who thinks he has a proof that there
can't be a god.  He only has to be someone who believes that the evidence
on the God question is at a similar level to the evidence on the werewolf
question."  [John McCarthy]