1
0
Fork 0
cl-sites/novaspec.org/cl/f_values.html
2025-02-05 18:52:26 +01:00

378 lines
No EOL
7.5 KiB
HTML

<!DOCTYPE HTML>
<HTML LANG="en-us"
><HEAD
><TITLE
>values | Common Lisp Nova Spec</TITLE
><META CHARSET="US-ASCII"
><LINK REL="canonical" HREF="f_values.html"
><LINK REL="next" HREF="f_values-list.html" TYPE="text/html" TITLE="values-list"
><LINK REL="prev" HREF="f_multiple-value-setq.html" TYPE="text/html" TITLE="multiple-value-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_values.html"
>values</A
></SPAN
></DIV
><DIV CLASS="apropos"
><DIV CLASS="apropos-io"
><A HREF="f_multiple-value-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_values-list.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="values"
></SPAN
><B
>values</B
></TD
><TD ALIGN="RIGHT" VALIGN="BASELINE" WIDTH="0" NOWRAP="NOWRAP" CLASS="ftype"
><I
>Accessor</I
></TD
></TR
></TABLE
><HR
></DIV
><UL CLASS="subtoc"
></UL
><DL
><DT
><B
>Syntax</B
></DT
><DD
><P CLASS="j"
><B
>values</B
> <SPAN CLASS="cmtt"
>&amp;rest</SPAN
> <SPAN CLASS="cmssi"
>object</SPAN
> <SPAN CLASS="arrow"
>&#8594;</SPAN
> {<VAR CLASS="param"
>object</VAR
>}*</P
><P CLASS="j"
><B
>(setf (values</B
> <SPAN CLASS="cmtt"
>&amp;rest</SPAN
> <SPAN CLASS="cmssi"
>place</SPAN
><B
>)</B
> <SPAN CLASS="cmssi"
>new-values</SPAN
><B
>)</B
></P
></DD
><DT
><B
>Arguments and Values</B
></DT
><DD
><P CLASS="j"
><VAR CLASS="param"
>object</VAR
> &#8212; an <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>place</VAR
> &#8212; a <A HREF="26_1_Glossary.html#place"
><EM CLASS="term"
>place</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>new-value</VAR
> &#8212; an <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</EM
></A
>.</P
></DD
><DT
><B
>Description</B
></DT
><DD
><P CLASS="j"
><A HREF="f_values.html" CLASS="funref"
><B
>values</B
></A
> returns the <VAR CLASS="param"
>objects</VAR
> as <A HREF="26_1_Glossary.html#multiple_values"
><EM CLASS="term"
>multiple values</EM
></A
><SPAN CLASS="meaning"
><SUB CLASS="sub"
><SPAN CLASS="cmr"
>2</SPAN
></SUB
></SPAN
>. </P
><P CLASS="j"
><A HREF="f_setf.html" CLASS="macref"
><B
>setf</B
></A
> of <A HREF="f_values.html" CLASS="funref"
><B
>values</B
></A
> is used to store the <A HREF="26_1_Glossary.html#multiple_values"
><EM CLASS="term"
>multiple values</EM
></A
><SPAN CLASS="meaning"
><SUB CLASS="sub"
><SPAN CLASS="cmr"
>2</SPAN
></SUB
></SPAN
> <VAR CLASS="param"
>new-values</VAR
> into the <VAR CLASS="param"
>places</VAR
>. See <A HREF="5_1_Generalized_Reference.html#sec_5_1_2_3" CLASS="secref"
><SPAN CLASS="cmr"
>Section</SPAN
> <SPAN CLASS="cmr"
>5.1.2.3</SPAN
> <SPAN CLASS="cmr"
>(VALUES</SPAN
> <SPAN CLASS="cmr"
>Forms</SPAN
> <SPAN CLASS="cmr"
>as</SPAN
> <SPAN CLASS="cmr"
>Places)</SPAN
></A
>.</P
></DD
><DT
><B
>Examples</B
></DT
><DD
><PRE CLASS="screen"
> (values) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> <SPAN CLASS="cmsy"
>&#10216;</SPAN
><I
>no</I
> <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>values</EM
></A
><SPAN CLASS="cmsy"
>&#10217;</SPAN
>
(values 1) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 1
(values 1 2) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 1, 2
(values 1 2 3) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 1, 2, 3
(values (values 1 2 3) 4 5) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 1, 4, 5
(defun polar (x y)
(values (sqrt (+ (* x x) (* y y))) (atan y x))) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> POLAR
(multiple-value-bind (r theta) (polar 3.0 4.0)
(vector r theta))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> #(5.0 0.927295)</PRE
><P CLASS="j"
>Sometimes it is desirable to indicate explicitly that a function returns exactly one value. For example, the function</P
><PRE CLASS="screen"
>(defun foo (x y)
(floor (+ x y) y)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> FOO</PRE
><P CLASS="j"
>returns two values because <A HREF="f_floor.html" CLASS="funref"
><B
>floor</B
></A
> returns two values. It may be that the second value makes no sense, or that for efficiency reasons it is desired not to compute the second value. <A HREF="f_values.html" CLASS="funref"
><B
>values</B
></A
> is the standard idiom for indicating that only one value is to be returned:</P
><PRE CLASS="screen"
>(defun foo (x y)
(values (floor (+ x y) y))) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> FOO</PRE
><P CLASS="j"
>This works because <A HREF="f_values.html" CLASS="funref"
><B
>values</B
></A
> returns exactly one value for each of <VAR CLASS="param"
>args</VAR
>; as for any function call, if any of <VAR CLASS="param"
>args</VAR
> produces more than one value, all but the first are discarded.</P
></DD
><DT
><B
>See Also</B
></DT
><DD
><P CLASS="j"
><A HREF="f_values-list.html" CLASS="funref"
><B
>values-list</B
></A
>, <A HREF="f_multiple-value-bind.html" CLASS="macref"
><B
>multiple-value-bind</B
></A
>, <A HREF="v_multiple-values-limit.html" CLASS="conref"
><B
>multiple-values-limit</B
></A
>, <A HREF="3_1_Evaluation.html#sec_3_1" CLASS="secref"
><SPAN CLASS="cmr"
>Section</SPAN
> <SPAN CLASS="cmr"
>3.1</SPAN
> <SPAN CLASS="cmr"
>(Evaluation)</SPAN
></A
></P
></DD
><DT
><B
>Notes</B
></DT
><DD
><P CLASS="j"
>Since <A HREF="f_values.html" CLASS="funref"
><B
>values</B
></A
> is a <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>function</EM
></A
>, not a <A HREF="26_1_Glossary.html#macro"
><EM CLASS="term"
>macro</EM
></A
> or <A HREF="26_1_Glossary.html#special_form"
><EM CLASS="term"
>special form</EM
></A
>, it receives as <A HREF="26_1_Glossary.html#argument"
><EM CLASS="term"
>arguments</EM
></A
> only the <A HREF="26_1_Glossary.html#primary_value"
><EM CLASS="term"
>primary values</EM
></A
> of its <A HREF="26_1_Glossary.html#argument"
><EM CLASS="term"
>argument</EM
></A
> <A HREF="26_1_Glossary.html#form"
><EM CLASS="term"
>forms</EM
></A
>.</P
></DD
></DL
></DIV
></DIV
><DIV CLASS="footer"
><DIV CLASS="btmnav"
><A HREF="f_multiple-value-setq.html" CLASS="prev"
>&#8592;</A
><A HREF="f_values-list.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
>