User Tools


Differences

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

Link to this comparison view

cl:macros:rotatef [2019/09/14 05:00]
cl:macros:rotatef [2019/09/20 08:00] (current)
Line 1: Line 1:
 +====== Macro ROTATEF ======
 +
 +====Syntax====
 +  * rotatef //​place''​*''//​ → **[[CL:​Constant Variables:​nil]]**
 +
 +====Arguments and Values====
 +  * //place// - a //​[[CL:​Glossary:​place]]//​.
 +
 +====Description====
 +**rotatef** modifies the values of each //place// by rotating values from one //place// into another.
 +
 +If a //place// produces more values than there are store variables, the extra values are ignored. If a //place// produces fewer values than there are store variables, the missing values are set to **[[CL:​Constant Variables:​nil]]**.
 +
 +In the form ''​(rotatef place1 place2 ... placen)'',​ the values in ''​place1''​ through ''​placen''​ are //​[[CL:​Glossary:​read]]//​ and //​[[CL:​Glossary:​written]]//​. Values 2 through ''​n''​ and value 1 are then stored into ''​place1''​ through ''​placen''​. It is as if all the places form an end-around shift register that is rotated one place to the left, with the value of ''​place1''​ being shifted around the end to ''​placen''​.
 +
 +For information about the //​[[CL:​Glossary:​evaluation]]//​ of //​[[CL:​Glossary:​subforms]]//​ of //places//, see section {\secref\GenRefSubFormEval}.
 +
 +====Examples==== ​
 +<​blockquote> ​
 +(let ((n 0) 
 +      (x (list 'a 'b 'c 'd 'e 'f '​g))) ​
 +  (rotatef ​
 +    (nth (incf n) x) 
 +    (nth (incf n) x) 
 +    (nth (incf n) x)) 
 +  x) <r>(A C D B E F G)</​r>​
 +</​blockquote>​
 +
 +====Affected By====
 +None.
 +
 +====Exceptional Situations====
 +None.
 +
 +====See Also====
 +  * **[[CL:​Macros:​define-setf-expander|Macro DEFINE-SETF-EXPANDER]]**
 +  * **[[CL:​Macros:​defsetf|Macro DEFSETF]]**
 +  * **[[CL:​Macros:​setf|Macro SETF]]**
 +  * **[[CL:​Macros:​shiftf|Macro SHIFTF]]**
 +  * **[[CL:​Variables:​*macroexpand-hook*|Variable *MACROEXPAND-HOOK*]]**
 +  * {\secref\GeneralizedReference}
 +
 +====Notes====
 +The effect of ''​(rotatef //place1// //place2// ... //​placen//​)''​ is roughly equivalent to
 +
 +<​blockquote>​
 +(psetf //place1// //place2//
 +       //​place2//​ //​place3// ​
 +       ​... ​
 +       //​placen//​ //place1//)
 +</​blockquote>​
 +
 +except that the latter would evaluate any //​[[CL:​Glossary:​subforms]]//​ of each ''​place''​ twice, whereas **rotatef** evaluates them once.
 +
 +\issue{SETF-MULTIPLE-STORE-VARIABLES:​ALLOW} \issue{PUSH-EVALUATION-ORDER:​FIRST-ITEM}