User Tools

Site Tools


ch2_1_splice-unquote

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
ch2_1_splice-unquote [2021/04/18 04:20] – created adminch2_1_splice-unquote [2022/03/06 11:37] (current) admin
Line 1: Line 1:
 **''SPLICE-UNQUOTE''** **''SPLICE-UNQUOTE''**
  
-Splice-unquote form expect one argument. Like unquote, it is ignored if appears outside of backquoted list. It works just like unquote in a backquoted list, with the difference when the unquoted item evaluates to list. In that case the elements of the list are spliced into the containing backquoted list. +Splice-unquote form expects one argument. Like unquote, it is ignored if it appears outside of backquoted list. Under backquoted list it works just like unquote, with the difference when the unquoted item evaluates to list. In that case the elements of the list are spliced into the containing backquoted list. The splice-unqoute has the special character '',@'' (comma-at).
  
-We have seen following example for unquote:+We have seen following example for ''UNQUOTE'':
  
 +<code lisp>
 +>`(a ,(list 1 2) c)    ; function LIST produces list
 +(A (1 2) C)            ; list (1 2) as sublist
 +</code>
  
-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.+With ''SPLICE-UNQUOTE'', we will get this:
  
 <code lisp> <code lisp>
->(setq b 3)       ; set value of symbol B +>`(a ,@(list 1 2) c)     
-+(A 1 2 C)               list (1 2) is spliced-in
->`(a ,c)        ; unquoted b +
-(A C)           symbols A and C are not evaled, but B is+
 </code> </code>
  
-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 ((unquote b) c))+>(setq b (list 'c 'd))   ; setting variable b to be list 
 +(C D)                    ; this is it 
 + 
 +>`(a ,@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
 </code> </code>
  
-Following example was shown for backquote:+Note that when ''SPLICE-UNQUOTE'' is used outside of backqouted list, it will be ignored, the expression evaluated, but it will not splice:
  
 <code lisp> <code lisp>
->`(a ,(+ 1 2) c)    ; backquoted list +>(list (list 34)    ; normal calls to LIST function   
-(C            form (+ 1 2) evaluated +(1 (2 3) 4)               list (2 3is sublist
-</code> +
  
-If the evaluated element results in list, with unquoting it becomes sub-list of the backqouted list:+>(list ,(list 2 3) 4)   ; with comma outside of backqoute ..   
 +(1 (2 3) 4)               ; .. just gives the same result
  
-<code lisp> +>(list 1 ,@(list 2 34 and comma-at outside of backqoute ..  
->`(,(list 2) c   function LIST produces list +(1 (34              .. same result, will not splice 
-(A (1 2) C           list (1 2) as sublist +</code>
-</code> +
  
-See splice-unquote for further refinement. The forms BACKQUOTE, UNQUOTE and SPLICE-UNQUOTE are useful for writing macros.+The forms ''BACKQUOTE''''UNQUOTE'' and ''SPLICE-UNQUOTE'' are useful for writing macros.
ch2_1_splice-unquote.1618741244.txt.gz · Last modified: 2021/04/18 04:20 by admin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki