Macros

Macros

Arc's macro system is more similar to Lisp than to Scheme; an Arc macro resembles a function that generates code.

Macros in Arc typically use quote and quasiquote to generate the code, and use uniq to generate unique symbols.

For details on the internals of Arc macros, see macro internals.

mac name args [body ...]
Creates a macro.
>(mac mymac (a b) (+ a b))
#(tagged mac #<procedure: mymac>)
macex macro
Expands a macro.
>(macex '(let a 1 (pr a)))
((fn (a) (pr a)) 1)
macex1 macro
Expands a macro to one level.
>(macex1 '(let a 1 (pr a)))
(with (a 1) (pr a))
uniq
Generates a unique symbol.
>(uniq)
gs2140
w/uniq names [body ...]
Assigns a unique symbol to each name in names and executes body. names can either be a single symbol or a list of symbols.
>(w/uniq (a b c) (prn a b c))
gs2141gs2142gs2143

gs2141
quasiquote arg
The backquote ` is shorthand for quasiquote, e.g. `(+ 1 2) is the same as (quasiquote (1 2)). Inside quasiquote, the unquote operator will cause the contents to be evaluated instead of quoated. The unquote-splicing operator will cause contents to be evaluated and spliced into the result. , is shorthand for unquote, and ,@ is shorthand for unquote-splicing.
>`((+ 1 2) ,(+ 3 4) ,@(list 5 6))
((+ 1 2) 7 5 6)
quote arg
The single quote ' is shorthand for quote, e.g. 'x is the same as (quote x)
>'(1 2 3)
(1 2 3)

Copyright 2008 Ken Shirriff.