User Tools

Site Tools


ch2_1_setf

Differences

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

Link to this comparison view

Next revision
Previous revision
ch2_1_setf [2022/02/20 04:44] – created adminch2_1_setf [2025/01/23 05:45] (current) admin
Line 1: Line 1:
 **''SETF''** **''SETF''**
  
-''SETF'' assigns values to //places//, accepts any number of arguments. The odd (first, third etc.) arguments, if they are not symbols, are evaled, but the result can represent //place//. The even (second, fourth etc.) arguments are evaled and the value is assigned to that //place//. The last set value is returned.+''SETF'' assigns values to //places//, accepts any number of arguments. The odd (first, third etc.) arguments, if they are not symbols, are evaled, and the result should represent //place//. The even (second, fourth etc.) arguments are evaled and the value is assigned to that //place//. The last set value is returned.
  
 ''SETF'' can be used just like ''SETQ'' to assign values to symbols: ''SETF'' can be used just like ''SETQ'' to assign values to symbols:
Line 10: Line 10:
 </code> </code>
  
-//Places// are returned from several //accessor// functions, like ''CAR'', ''CDR'' etc.+//Places// are returned from several //accessor// functions - in LabLISP they are only the list-related functions: all the ''CAR'', ''CDR'' combinations, the ''FIRST'' to ''TENTH'', ''REST'', ''NTH'' and ''NTHCDR''.
    
 <code lisp> <code lisp>
->(setq li '(a b c))           ; prepare list LI for this example+>(setq li '(a b c))   ; prepare list LI for this example
 (A B C) (A B C)
  
Line 20: Line 20:
  
 >li >li
-(D C B)+(D C B)               ; value in the list was changed
 </code> </code>
 +
 +With ''SETF'', it is possible to create cyclic lists:
 +
 +<code lisp>
 +>(setf (cdddr li) li) ; connecting the end of the list to the start
 +#1=(D B C . #1#)      ; LabLISP will print it with anchor and link 
 +</code>
 +
 +It is not recommended to use this dangerous feature. In the present state, LabLISP has just very rudimental protection against cyclic lists. Trying to work with cyclic lists might crash, produce memory leaks, or get stuck in infinite loops on C++ level. 
 +
 +
  
ch2_1_setf.1645357450.txt.gz · Last modified: 2022/02/20 04:44 by admin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki