[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lightweight syntax: a dissident view
- From: steve donovan <steve.j.donovan@...>
- Date: Thu, 25 Nov 2010 08:30:02 +0200
On Wed, Nov 24, 2010 at 9:23 PM, Luiz Henrique de Figueiredo
<lhf@tecgraf.puc-rio.br> wrote:
> To allow people to experiment with that syntax, here is an implementation
> using a token filter written in C.
>
> It converts
> \x,y,z(x+(x-2)*g(x,y,z-2*(x+y))-y*z)
> to
> function(x,y,z) return x+(x-2)*g(x,y,z-2*(x+y))-y*z end
>
The LuaMacro[1] equivalent is:
macro.define ('\\', {'args','body';handle_parms =
true},'function(args) return body end',
function(ls) -- grab the lambda
-- these guys return _arrays_ of token-lists. We use '' as the delim
-- so commas don't split the results
local args = macro.grab_parameters('(','')[1]
local body = macro.grab_parameters(')','')[1]
return args,body
end
)
Note that there is a mingw-compiled version of Lua with the
token-filter patch available for download as well; a LfW compatible
lua5.1.dll can be made up if there's interest.
steve d.
[1] http://luaforge.net/frs/?group_id=328;
See examples.lua for the definition.