---------------------------------------------------------
-- the "-{...}" means that we're going to do compile-time
-- stuff (here, syntax extension)
---------------------------------------------------------
-{ block:
------------------------------------------------------
-- Register the additional keywords in mlp.lexer
------------------------------------------------------
mlp.lexer:add{ "let", "in" }
------------------------------------------------------
-- Extend the expression parser; code generation is
-- delegated to the function let_in_builder() below.
------------------------------------------------------
mlp.expr:add{
"let", mlp.id, "=", mlp.expr, "in", mlp.expr,
builder = let_in_builder }
------------------------------------------------------
-- This creates the code returned by the macro.
-- Notice the holes-in-quote-in-splice.
------------------------------------------------------
local function let_in_builder (x)
local variable, value, expr = unpack (x)
return +{
function (-{variable})
return -{expr}
end (-{value}) }
end
} -- back to "normal" code
a, b, c = 1, 1, -2
roots = let sqrt_delta = (b^2-4*a*c)^0.5 in
{ (sqrt_delta-b)/(2*a), (-sqrt_delta-b)/(2*a) }
12/20/07
MetaLua
MetaLua is a very interesting metaprogramming Lua dialect.