ch2_1_unquote
This is an old revision of the document!
UNQUOTE
Unquote form expect one argument. If unquote appears outside of backquoted list, it is ignored, and the argument is evaluated normally. But within a backquoted list, or any of its sub-lists, we can switch some symbols or sub-lists back to code mode with unquote character ,
(comma), which reader expands to unquote form.
>(setq b 3) ; set value of symbol B 3 >`(a ,b c) ; unquoted B in backquouted list (A 3 C) ; symbols A and C are not evaled, but B is
The last command is expanded to
>(backquote (a (unquote b) c))
Following example was shown for backquote:
>`(a ,(+ 1 2) c) ; backquoted list (A 3 C) ; form (+ 1 2) evaluated
If the evaluated element results in list, with unquoting it becomes sub-list of the backqouted list:
>`(a ,(list 1 2) c) ; function LIST produces list (A (1 2) C) ; list (1 2) as sublist
See splice-unquote for further refinement. The forms BACKQUOTE
, UNQUOTE
and SPLICE-UNQUOTE
are useful for writing macros.
ch2_1_unquote.1645623243.txt.gz · Last modified: 2022/02/23 06:34 by admin