1
0
Fork 0
cl-sites/novaspec.org/cl/f_symbol-value.html

393 lines
7.2 KiB
HTML
Raw Normal View History

2025-02-05 18:52:26 +01:00
<!DOCTYPE HTML>
<HTML LANG="en-us"
><HEAD
><TITLE
>symbol-value | Common Lisp Nova Spec</TITLE
><META CHARSET="US-ASCII"
><LINK REL="canonical" HREF="f_symbol-value.html"
><LINK REL="next" HREF="f_get.html" TYPE="text/html" TITLE="get"
><LINK REL="prev" HREF="f_symbol-plist.html" TYPE="text/html" TITLE="symbol-plist"
><LINK REL="up" HREF="10_2_Symbols_Dictionary.html" TYPE="text/html" TITLE="10.2 Symbols 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="10_Symbols.html"
>10. Symbols</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="10_2_Symbols_Dictionary.html"
>10.2 Symbols Dictionary</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="f_symbol-value.html"
>symbol-value</A
></SPAN
></DIV
><DIV CLASS="apropos"
><DIV CLASS="apropos-io"
><A HREF="f_symbol-plist.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_get.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="symbol-value"
></SPAN
><B
>symbol-value</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
>symbol-value</B
> <SPAN CLASS="cmssi"
>symbol</SPAN
> <SPAN CLASS="arrow"
>&#8594;</SPAN
> <SPAN CLASS="cmssi"
>value</SPAN
></P
><P CLASS="j"
><B
>(setf (symbol-value</B
> <SPAN CLASS="cmssi"
>symbol</SPAN
><B
>)</B
> <SPAN CLASS="cmssi"
>new-value</SPAN
><B
>)</B
></P
></DD
><DT
><B
>Arguments and Values</B
></DT
><DD
><P CLASS="j"
><VAR CLASS="param"
>symbol</VAR
> &#8212; a <A HREF="26_1_Glossary.html#symbol"
><EM CLASS="term"
>symbol</EM
></A
> that must have a <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>value</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>value</VAR
>, <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="26_1_Glossary.html#access"
><EM CLASS="term"
>Accesses</EM
></A
> the <A HREF="26_1_Glossary.html#symbol"
><EM CLASS="term"
>symbol</EM
></A
>&#8217;s <A HREF="26_1_Glossary.html#value_cell"
><EM CLASS="term"
>value cell</EM
></A
>.</P
></DD
><DT
><B
>Examples</B
></DT
><DD
><PRE CLASS="screen"
>(setf (symbol-value 'a) 1) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 1
(symbol-value 'a) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 1
;; SYMBOL-VALUE cannot see lexical variables.
(let ((a 2)) (symbol-value 'a)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 1
(let ((a 2)) (setq a 3) (symbol-value 'a)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 1
;; SYMBOL-VALUE can see dynamic variables.
(let ((a 2))
(declare (special a))
(symbol-value 'a)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 2
(let ((a 2))
(declare (special a))
(setq a 3)
(symbol-value 'a)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 3
(let ((a 2))
(setf (symbol-value 'a) 3)
a) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 2
a <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 3
(symbol-value 'a) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 3
(let ((a 4))
(declare (special a))
(let ((b (symbol-value 'a)))
(setf (symbol-value 'a) 5)
(values a b))) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 5, 4
a <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 3
(symbol-value :any-keyword) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> :ANY-KEYWORD
(symbol-value 'nil) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> NIL
(symbol-value '()) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> NIL
;; The precision of this next one is <A HREF="26_1_Glossary.html#implementation-dependent"
><EM CLASS="term"
>implementation-dependent</EM
></A
>.
(symbol-value 'pi) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 3.141592653589793d0</PRE
></DD
><DT
><B
>Affected By</B
></DT
><DD
><P CLASS="j"
><A HREF="f_makunbound.html" CLASS="funref"
><B
>makunbound</B
></A
>, <A HREF="f_set.html" CLASS="funref"
><B
>set</B
></A
>, <A HREF="f_setq.html" CLASS="specref"
><B
>setq</B
></A
></P
></DD
><DT
><B
>Exceptional Situations</B
></DT
><DD
><P CLASS="j"
>Should signal an error of <A HREF="26_1_Glossary.html#type"
><EM CLASS="term"
>type</EM
></A
> <A HREF="t_type-error.html" CLASS="typeref"
><B
>type-error</B
></A
> if <VAR CLASS="param"
>symbol</VAR
> is not a <A HREF="26_1_Glossary.html#symbol"
><EM CLASS="term"
>symbol</EM
></A
>. </P
><P CLASS="j"
>Should signal <A HREF="t_unbound-variable.html" CLASS="typeref"
><B
>unbound-variable</B
></A
> if <VAR CLASS="param"
>symbol</VAR
> is <A HREF="26_1_Glossary.html#unbound"
><EM CLASS="term"
>unbound</EM
></A
> and an attempt is made to <A HREF="26_1_Glossary.html#read"
><EM CLASS="term"
>read</EM
></A
> its <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>value</EM
></A
>. (No such error is signaled on an attempt to <A HREF="26_1_Glossary.html#write"
><EM CLASS="term"
>write</EM
></A
> its <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>value</EM
></A
>.)</P
></DD
><DT
><B
>See Also</B
></DT
><DD
><P CLASS="j"
><A HREF="f_boundp.html" CLASS="funref"
><B
>boundp</B
></A
>, <A HREF="f_makunbound.html" CLASS="funref"
><B
>makunbound</B
></A
>, <A HREF="f_set.html" CLASS="funref"
><B
>set</B
></A
>, <A HREF="f_setq.html" CLASS="specref"
><B
>setq</B
></A
></P
></DD
><DT
><B
>Notes</B
></DT
><DD
><P CLASS="j"
><A HREF="f_symbol-value.html" CLASS="funref"
><B
>symbol-value</B
></A
> can be used to get the value of a <A HREF="26_1_Glossary.html#constant_variable"
><EM CLASS="term"
>constant variable</EM
></A
>. <A HREF="f_symbol-value.html" CLASS="funref"
><B
>symbol-value</B
></A
> cannot <A HREF="26_1_Glossary.html#access"
><EM CLASS="term"
>access</EM
></A
> the value of a <A HREF="26_1_Glossary.html#lexical_variable"
><EM CLASS="term"
>lexical variable</EM
></A
>.</P
></DD
></DL
></DIV
></DIV
><DIV CLASS="footer"
><DIV CLASS="btmnav"
><A HREF="f_symbol-plist.html" CLASS="prev"
>&#8592;</A
><A HREF="f_get.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
>