Copyright (C) 2000-2012 |
GNU Info (librep.info)BackquotingBackquoting ----------- As seen in the previous sections, macros are a very powerful mechanism of defining new control structures. However due to the need to create the expansion, i.e. the form that will be actually evaluated, they can often be complex to write and understand. We have already seen that constants may be produced through the use of the quote-mark (Note: Quoting), here another form of quoting is described, where only some of the quoted object is actually constant. This is known as "backquoting", since it is introduced by the backquote character ``', a shortcut for the `backquote' macro. - Macro: backquote arg Constructs a new version of ARG (a list). All parts of LIST are preserved except for expressions introduced by comma (`,') characters, which are evaluated and spliced into the list. For example: `(1 2 ,(+ 1 2)) => (1 2 3) Also, the `,@' prefix will splice the following _list_ into the output list, at the same level: `(1 2 ,@(list 3)) => (1 2 3) Backquoting allows macros expansions to be created from static templates. For example the `when' macro shown in the previous sections can be rewritten as: (defmacro when (condition #!rest body) `(cond (,condition ,@body))) which is easier to read, since it is a lot closer to the actual expansion. automatically generated by info2www version 1.2.2.9 |