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

Both sides previous revisionPrevious revision
Next revision
Previous revision
ch2_1_splice-unquote [2021/04/18 04:43] adminch2_1_splice-unquote [2022/03/06 11:37] (current) admin
Line 3: Line 3:
 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). 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> <code lisp>
Line 10: Line 10:
 </code> </code>
  
-With splice-unqoute, we will get this:+With ''SPLICE-UNQUOTE'', we will get this:
  
 <code lisp> <code lisp>
Line 17: Line 17:
 </code> </code>
  
-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.+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>
 >(setq b (list 'c 'd))   ; setting variable b to be list >(setq b (list 'c 'd))   ; setting variable b to be list
-(C D)            +(C D)                    ; this is it 
-         ; this is it+
 >`(a ,@b e f)  >`(a ,@b e f) 
 (A C D E F)              ; elements of list (C D) spliced-in (A C D E F)              ; elements of list (C D) spliced-in
Line 30: Line 30:
 </code> </code>
  
-Note that when splice-unqoute is used outside of backqouted list, it will be ignored, the expression evaluated, but it will not splice:+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>
Line 36: Line 36:
 (1 (2 3) 4)               ; list (2 3) is sublist (1 (2 3) 4)               ; list (2 3) is sublist
  
->(list 1 ,(list 2 3) 4)   ; with comma out of backqoute ..  +>(list 1 ,(list 2 3) 4)   ; with comma outside of backqoute ..  
 (1 (2 3) 4)               ; .. just gives the same result (1 (2 3) 4)               ; .. just gives the same result
  
->(list 1 ,@(list 2 3) 4)  ; and comma-at out of backqoute .. +>(list 1 ,@(list 2 3) 4)  ; and comma-at outside of backqoute .. 
 (1 (2 3) 4)               ; .. same result, will not splice (1 (2 3) 4)               ; .. same result, will not splice
 </code> </code>
  
-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.1618742580.txt.gz · Last modified: 2021/04/18 04:43 by admin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki