This reminded me of gotchas one can fall to when defining some Lisp macro from scratch. So I decided to test whether rotatef works exactly like Python's multiple assignment:
(let ((A (vector 2 1)))
(rotatef (elt A
0)
(elt A
(1- (elt A 0))))
A)
It returns a changed vector as if indexes were saved.
I am not sure which should be considered the right behavior.
From the standard[0], "In the form (rotatef place1 place2 ... placen), the values in place1 through placen are read and 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." The key word being place Once (elt A 0) and (elt A (1- (elt A 0))) are evaluated rotatef keeps track of the places and the values at those locations. It then assigns the values to the places; it does not reevaluate the expressions.
There is also setf and psetf which in the examples I'm giving evaluate from lowest suffix to highest (same as todd8).
Comments
This reminded me of gotchas one can fall to when defining some Lisp macro from scratch. So I decided to test whether rotatef works exactly like Python's multiple assignment:
It returns a changed vector as if indexes were saved.I am not sure which should be considered the right behavior.
From the standard[0], "In the form (rotatef place1 place2 ... placen), the values in place1 through placen are read and 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." The key word being place Once (elt A 0) and (elt A (1- (elt A 0))) are evaluated rotatef keeps track of the places and the values at those locations. It then assigns the values to the places; it does not reevaluate the expressions.
There is also setf and psetf which in the examples I'm giving evaluate from lowest suffix to highest (same as todd8).
[0] http://clhs.lisp.se/Body/m_rotate.htm