lua-users home
lua-l archive

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

On 11/1/07, steve donovan <> wrote:
Note the hoops we have to go through to embed a statement in an

That's occasionally irritating when writing regular code, but it's often really problematic for metaprogramming. There's an added AST node `Stat{ block, expr } in metalua to work around this: it's accepted where an _expression_ is expected, the statements block is evaluated, then the _expression_ (in the block's scope), and the result of that _expression_ is the value of the whole `Stat{ } node.

There's no official syntax for it, because I'm not convinced it's worth it, but it's trivial to add one, e.g.:

-{ mlp.expr:add{ 'do', mlp.block, 'then', mlp.expr, builder = 'Stat' } }
roots = do local sqrt_delta = (b^2-4*a*c) then { (-b-sqrt_delta)/2*a; (-b+sqrt_delta)/2*a }

There are a couple of other extra goodies that make special sense for metaprogramming...

w.r.t. handling errors properly in multi-stage programming, Laurence Tratt did a really interesting job on Converge (, and metalua will benefit from this work (the only non-trivial part is retaining compatibility with the vanilla Lua VM).