ch2_1_splice-unquote
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
ch2_1_splice-unquote [2021/04/18 04:20] – created admin | ch2_1_splice-unquote [2022/03/06 11:37] (current) – admin | ||
---|---|---|---|
Line 1: | Line 1: | ||
**'' | **'' | ||
- | Splice-unquote form expect | + | Splice-unquote form expects |
- | We have seen following example for unquote: | + | We have seen following example for '' |
+ | <code lisp> | ||
+ | >`(a ,(list 1 2) c) ; function LIST produces list | ||
+ | (A (1 2) C) ; list (1 2) as sublist | ||
+ | </ | ||
- | 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 | + | With '' |
<code lisp> | <code lisp> | ||
- | >(setq b 3) ; set value of symbol B | + | >`(a ,@(list 1 2) c) |
- | 3 | + | (A 1 2 C) |
- | >`(a ,b c) ; unquoted b | + | |
- | (A 3 C) | + | |
</ | </ | ||
- | The last command is equivalent to | + | The elements of the spliced-in sublist are freshly consed, which means that when we are splicing an existing list, it will not be modified. Since version 1.2.9.1 we can also splice cyclic or dotted lists: In the freshly consed copy, for cyclic lists it will break the cycle, and for dotted lists simply ignores the danglig atom. |
<code lisp> | <code lisp> | ||
- | >(backquote | + | >(setq b (list 'c ' |
+ | (C D) ; this is it | ||
+ | |||
+ | >`(a ,@b e f) | ||
+ | (A C D E F) ; elements of list (C D) spliced-in | ||
+ | |||
+ | >b | ||
+ | (C D) ; B has still the original list, without the E F tail | ||
</ | </ | ||
- | Following example was shown for backquote: | + | Note that when '' |
<code lisp> | <code lisp> | ||
- | >`(a ,(+ 1 2) c) ; backquoted list | + | >(list 1 (list 2 3) 4) ; normal calls to LIST function |
- | (A 3 C) | + | (1 (2 3) 4) ; list (2 3) is sublist |
- | </ | + | |
- | If the evaluated element results in list, with unquoting it becomes sub-list | + | >(list 1 ,(list 2 3) 4) ; |
+ | (1 (2 3) 4) ; .. just gives the same result | ||
- | <code lisp> | + | >(list 1 ,@(list 2 3) 4) ; and comma-at outside of backqoute .. |
- | >`(a , | + | (1 (2 3) 4) |
- | (A (1 2) C) ; list (1 2) as sublist | + | </ |
- | </ | + | |
- | See splice-unquote for further refinement. | + | The forms '' |
ch2_1_splice-unquote.1618741244.txt.gz · Last modified: 2021/04/18 04:20 by admin