]> git.lizzy.rs Git - metalua.git/blob - doc/manual/dollar-ref.tex
fix CRLF
[metalua.git] / doc / manual / dollar-ref.tex
1 \section[Dollar extension]{{\tt dollar}: generic syntax for macros}
2 When you write a short-lived macro which takes reasonably short arguments, you
3 generally don't want to write a supporting syntax for it. The dollar library
4 allows you to call it in a generic way: if you store your macro in the table
5 {\tt mlp.macros}, say as function {\tt mlp.macros.foobar}, then you can call it
6 in your code as {\tt\$foobar(arg1, arg2...)}: it will receive as parameters the
7 ASTs of the pseudo-call's arguments.
8
9 \paragraph{Example}~
10 \begin{verbatim}
11 -{ block:
12    require 'dollar'
13    function doller.LOG(id)
14       match id with `Id{ id_name } -> 
15          return +{ printf("%s = %s", id_name, 
16                           table.tostring(-{id})) }
17       end
18    end }
19
20 local x = { 1, 2, 3 }
21 $LOG(x) -- prints "x = { 1, 2, 3 }" when executed
22 \end{verbatim}