1 \section[Dollar extension]{{\tt dollar}: generic syntax for macros}
\r
2 When you write a short-lived macro which takes reasonably short arguments, you
\r
3 generally don't want to write a supporting syntax for it. The dollar library
\r
4 allows you to call it in a generic way: if you store your macro in the table
\r
5 {\tt mlp.macros}, say as function {\tt mlp.macros.foobar}, then you can call it
\r
6 in your code as {\tt\$foobar(arg1, arg2...)}: it will receive as parameters the
\r
7 ASTs of the pseudo-call's arguments.
\r
13 function doller.LOG(id)
\r
14 match id with `Id{ id_name } ->
\r
15 return +{ printf("%s = %s", id_name,
\r
16 table.tostring(-{id})) }
\r
20 local x = { 1, 2, 3 }
\r
21 $LOG(x) -- prints "x = { 1, 2, 3 }" when executed
\r