User Tools

Site Tools


ch2_1_unquote

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

Important is that if we unqoute pre-existing list, this original list will become sublist, not a copy. SPLICE-UNQUOTE is different in this.

See splice-unquote for further refinement. The forms BACKQUOTE, UNQUOTE and SPLICE-UNQUOTE are useful for writing macros.

ch2_1_unquote.txt · Last modified: 2022/02/25 01:47 by admin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki