1
0
Fork 0
cl-sites/novaspec.org/cl/f_psetq.html

326 lines
6.5 KiB
HTML
Raw Normal View History

2025-02-05 18:52:26 +01:00
<!DOCTYPE HTML>
<HTML LANG="en-us"
><HEAD
><TITLE
>psetq | Common Lisp Nova Spec</TITLE
><META CHARSET="US-ASCII"
><LINK REL="canonical" HREF="f_psetq.html"
><LINK REL="next" HREF="f_block.html" TYPE="text/html" TITLE="block"
><LINK REL="prev" HREF="f_setq.html" TYPE="text/html" TITLE="setq"
><LINK REL="up" HREF="5_3_Data_and_Control_Flow_Dictionary.html" TYPE="text/html" TITLE="5.3 Data and Control Flow Dictionary"
><LINK REL="start" HREF="index.html" TYPE="text/html" TITLE="Common Lisp Nova Spec"
><META NAME="VIEWPORT" CONTENT="width=device-width, initial-scale=1.0"
><LINK REL="STYLESHEET" HREF="dpans.css%3F3909942064.css"
><SCRIPT SRC="dpans.js%3F3909942064"
></SCRIPT
><SCRIPT SRC="apropos.js%3F3909942064"
></SCRIPT
></HEAD
><BODY
><DIV
><DIV CLASS="topnav"
><DIV CLASS="breadcrumb"
><SPAN CLASS="breadcrumb-item"
><A HREF="index.html"
>Common Lisp Nova Spec</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="5_Data_and_Control_Flow.html"
>5. Data and Control Flow</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="5_3_Data_and_Control_Flow_Dictionary.html"
>5.3 Data and Control Flow Dictionary</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="f_psetq.html"
>psetq</A
></SPAN
></DIV
><DIV CLASS="apropos"
><DIV CLASS="apropos-io"
><A HREF="f_setq.html" CLASS="prev"
>&#8592;</A
><SPAN ID="apropos-label"
>Apropos </SPAN
><INPUT ID="apropos" AUTOFOCUS="AUTOFOCUS" PLACEHOLDER="Type here to search" ONINPUT="aproposInput(this);" ONKEYUP="aproposKeyup(event);" ONCHANGE="aproposChange(this);" ONFOCUS="aproposFocus(this);" ONFOCUSOUT="aproposFocusout(this);"
><A HREF="f_block.html" CLASS="next"
>&#8594;</A
></DIV
><DIV ID="apropos-res"
></DIV
></DIV
></DIV
><DIV CLASS="matter"
><DIV CLASS="com"
><DIV CLASS="begincom"
><HR
><TABLE WIDTH="100%" CELLSPACING="0" CELLPADDING="0"
><TR
><TD ALIGN="LEFT" VALIGN="BASELINE" WIDTH="100%" CLASS="name"
><SPAN CLASS="idx" DATA-KIND="idxref" DATA-TERM="psetq"
></SPAN
><B
>psetq</B
></TD
><TD ALIGN="RIGHT" VALIGN="BASELINE" WIDTH="0" NOWRAP="NOWRAP" CLASS="ftype"
><I
>Macro</I
></TD
></TR
></TABLE
><HR
></DIV
><UL CLASS="subtoc"
></UL
><DL
><DT
><B
>Syntax</B
></DT
><DD
><P CLASS="j"
><B
>psetq</B
> {&#8595;<VAR CLASS="param"
>pair</VAR
>}* <SPAN CLASS="arrow"
>&#8594;</SPAN
> <SPAN CLASS="misc"
><B
>nil</B
></SPAN
></P
><TABLE CELLSPACING="0" CELLPADDING="0" RULES="GROUPS" STYLE="margin: 1ex 0"
><TBODY
><TR
><TD ALIGN="LEFT" VALIGN="BASELINE" STYLE=";padding-right:3px"
></TD
><TD ALIGN="LEFT" VALIGN="BASELINE" STYLE="padding-left:3px;padding-right:3px"
><VAR CLASS="param"
>pair</VAR
><SPAN CLASS="cmssi"
>::</SPAN
><SPAN CLASS="cmr"
>=</SPAN
></TD
><TD ALIGN="LEFT" VALIGN="BASELINE" STYLE="padding-left:3px;"
> <SPAN CLASS="cmssi"
>var</SPAN
> <SPAN CLASS="cmssi"
>form</SPAN
></TD
></TR
></TBODY
></TABLE
></DD
><DT
><B
>Pronunciation</B
></DT
><DD
><P CLASS="j"
><A HREF="f_psetq.html" CLASS="macref"
><B
>psetq</B
></A
>: [ <B CLASS="b"
>p&#275; set ky&#252;</B
>&#8201;]</P
></DD
><DT
><B
>Arguments and Values</B
></DT
><DD
><P CLASS="j"
><VAR CLASS="param"
>var</VAR
> &#8212; a <A HREF="26_1_Glossary.html#symbol"
><EM CLASS="term"
>symbol</EM
></A
> naming a <A HREF="26_1_Glossary.html#variable"
><EM CLASS="term"
>variable</EM
></A
> other than a <A HREF="26_1_Glossary.html#constant_variable"
><EM CLASS="term"
>constant variable</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>form</VAR
> &#8212; a <A HREF="26_1_Glossary.html#form"
><EM CLASS="term"
>form</EM
></A
>.</P
></DD
><DT
><B
>Description</B
></DT
><DD
><P CLASS="j"
>Assigns values to <A HREF="26_1_Glossary.html#variable"
><EM CLASS="term"
>variables</EM
></A
>. </P
><P CLASS="j"
>This is just like <A HREF="f_setq.html" CLASS="specref"
><B
>setq</B
></A
>, except that the assignments happen &#8220;in parallel.&#8221; 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 <A HREF="f_setq.html" CLASS="specref"
><B
>setq</B
></A
>&#8217;s sequential assignment. </P
><P CLASS="j"
>If any <VAR CLASS="param"
>var</VAR
> refers to a <A HREF="26_1_Glossary.html#binding"
><EM CLASS="term"
>binding</EM
></A
> made by <A HREF="f_symbol-macrolet.html" CLASS="specref"
><B
>symbol-macrolet</B
></A
>, then that <VAR CLASS="param"
>var</VAR
> is treated as if <A HREF="f_setf.html" CLASS="macref"
><B
>psetf</B
></A
> (not <A HREF="f_psetq.html" CLASS="macref"
><B
>psetq</B
></A
>) had been used.</P
></DD
><DT
><B
>Examples</B
></DT
><DD
><PRE CLASS="screen"
> ;; A simple use of PSETQ to establish values for variables.
;; As a matter of style, many programmers would prefer SETQ
;; in a simple situation like this where parallel assignment
;; is not needed, but the two have equivalent effect.
(psetq a 1 b 2 c 3) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> NIL
a <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 1
b <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 2
c <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 3
;; Use of PSETQ to update values by parallel assignment.
;; The effect here is very different than if SETQ had been used.
(psetq a (1+ b) b (1+ a) c (+ a b)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> NIL
a <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 3
b <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 2
c <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 3
;; Use of PSETQ on a symbol macro.
(let ((x (list 10 20 30)))
(symbol-macrolet ((y (car x)) (z (cadr x)))
(psetq y (1+ z) z (1+ y))
(list x y z)))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> ((21 11 30) 21 11)
;; Use of parallel assignment to swap values of A and B.
(let ((a 1) (b 2))
(psetq a b b a)
(values a b))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 2, 1</PRE
></DD
><DT
><B
>Side Effects</B
></DT
><DD
><P CLASS="j"
>The values of <VAR CLASS="param"
>forms</VAR
> are assigned to <VAR CLASS="param"
>vars</VAR
>.</P
></DD
><DT
><B
>See Also</B
></DT
><DD
><P CLASS="j"
><A HREF="f_setf.html" CLASS="macref"
><B
>psetf</B
></A
>, <A HREF="f_setq.html" CLASS="specref"
><B
>setq</B
></A
></P
></DD
></DL
></DIV
></DIV
><DIV CLASS="footer"
><DIV CLASS="btmnav"
><A HREF="f_setq.html" CLASS="prev"
>&#8592;</A
><A HREF="f_block.html" CLASS="next"
>&#8594;</A
></DIV
><DIV CLASS="trail"
>Conversion to HTML copyright 2023 by Gilbert Baumann</DIV
></DIV
></DIV
><SCRIPT
>domReady();</SCRIPT
></BODY
></HTML
>