[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: [ANN] LuaMacro on LuaForge
- From: "steve donovan" <steve.j.donovan@...>
- Date: Mon, 3 Dec 2007 14:27:28 +0200
Hi guys,
A semi-official release:
http://luaforge.net/projects/luamacro/
The macro du jour is list comprehensions, using a syntax suggested by
Fabien and implemented with his MetaLua:
x = L{i for i = 1,5}
{1,2,3,4,5}
Such a statement does not actually require much transformation to be
valid Lua, if you use anonymous functions:
x = (function() local ls={}; for i = 1,5 do ls[#ls+1] = i; return ls end)()
It's possible to nest these 'list constructors' (I personally don't
like the term 'list comprehension')
x = L{L{j for j=1,3} for i=1,3}
{{1,2,3},{1,2,3},{1,2,3}}
There is also an implementation of the match/with statement as
discussed some time back.
Note: there is a limitation of macros; they cannot load modules,
except with a nasty fiddle:
For example, a simple macro which has the side-effect of trying to
load a module. If one switches off the token filter by setting FILTER
to nil, it seems to work.
macro.define('X',nil,function(ls)
local F = FILTER
FILTER = nil
require 'simple'
FILTER = f
return {}
end)
Thanks to Sérgio Medeiros for unearthing this bug.
steve d.