User Tools


Differences

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

Link to this comparison view

cl:macros:psetq [2019/07/14 17:00]
cl:macros:psetq [2019/10/19 05:00] (current)
Line 1: Line 1:
 +====== Macro PSETQ ======
 +
 +====Syntax====
 +  * **psetq** //​{pair''​*''​}//​ → //​[[CL:​Constant Variables:​nil]]//​
 +  ​
 +<​blockquote>​
 +//pair// ::= //var form//
 +</​blockquote>​
 +
 +====Arguments and Values====
 +  * //var// - a //​[[CL:​Glossary:​symbol]]//​ naming a //​[[CL:​Glossary:​variable]]//​ other than a //​[[CL:​Glossary:​constant variable]]//​.
 +  * //form// - a //​[[CL:​Glossary:​form]]//​.
 +
 +====Description====
 +Assigns values to //​[[CL:​Glossary:​variables]]//​.
 +
 +This is just like **[[CL:​Special Operators:​setq]]**,​ except that the assignments happen "in parallel."​ That is, first all of the forms are evaluated, and only then are the variables set to the resulting values. In this way, the assignment to one variable does not affect the value computation of another in the way that would occur with **[[CL:​Special Operators:​setq]]**'​s sequential assignment.
 +
 +If any //var// refers to a //​[[CL:​Glossary:​binding]]//​ made by **[[CL:​Special Operators:​symbol-macrolet]]**,​ then that //var// is treated as if **[[CL:​Macros:​psetf]]** (not **psetq**) had been used.
 +
 +====Examples====
 +A simple use of **psetq** to establish values for variables. As a matter of style, many programmers would prefer **[[CL:​Special Operators:​setq]]** in a simple situation like this where parallel assignment is not needed, but the two have equivalent effect. ​
 +<​blockquote>​
 +;;; TODO condemn toplevel PSETQ
 +
 +(psetq a 1 b 2 c 3) <​r>​NIL</​r>​
 +a <​r>​1</​r>​
 +b <​r>​2</​r>​
 +c <​r>​3</​r>​
 +</​blockquote>​
 +
 +Use of **psetq** to update values by parallel assignment. The effect here is very different than if **[[CL:​Special Operators:​setq]]** had been used.
 +
 +<​blockquote>​
 +(psetq a ([[CL:​Functions:​math-one-plus|1+]] b) b ([[CL:​Functions:​math-one-plus|1+]] a) c ([[CL:​Functions:​math-add|+]] a b)) <​r>​NIL</​r>​
 +a <​r>​3</​r>​
 +b <​r>​2</​r>​
 +c <​r>​3</​r>​
 +
 +</​blockquote>​
 +
 +Use of **psetq** on a symbol macro.
 +
 +<​blockquote>​
 +([[CL:​Special Operators:​let]] ((x ([[CL:​Functions:​list]] 10 20 30)))
 +  ([[CL:​Special Operators:​symbol-macrolet]] ((y ([[CL:​Functions:​car]] x)) (z ([[CL:​Functions:​cadr]] x)))
 +    (psetq y ([[CL:​Functions:​math-one-plus|1+]] z) z ([[CL:​Functions:​math-one-plus|1+]] y))
 +    ([[CL:​Functions:​list]] x y z))) 
 +<​r>​((21 11 30) 21 11)</​r>​
 +</​blockquote>​
 +
 +Use of parallel assignment to swap values of A and B.
 +
 +<​blockquote>​
 +([[CL:​Special Operators:​let]] ((a 1) (b 2)) 
 +  (psetq a b b a) 
 +  ([[CL:​Functions:​values]] a b)) 
 +<r>2
 +1</r>
 +</​blockquote>​
 +
 +====Side Effects====
 +The values of //forms// are assigned to //vars//.
 +
 +====Affected By====
 +None.
 +
 +====Exceptional Situations====
 +None.
 +
 +====See Also====
 +  * **[[CL:​Macros:​psetf|Macro PSETF]]**
 +  * **[[CL:​Special Operators:​setq|Special Operator SETQ]]**
 +
 +====Notes====
 +None.
 +
 +\issue{SYMBOL-MACROLET-SEMANTICS:​SPECIAL-FORM}