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

528 lines
No EOL
10 KiB
HTML

<!DOCTYPE HTML>
<HTML LANG="en-us"
><HEAD
><TITLE
>get | Common Lisp Nova Spec</TITLE
><META CHARSET="US-ASCII"
><LINK REL="canonical" HREF="f_get.html"
><LINK REL="next" HREF="f_remprop.html" TYPE="text/html" TITLE="remprop"
><LINK REL="prev" HREF="f_symbol-value.html" TYPE="text/html" TITLE="symbol-value"
><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_get.html"
>get</A
></SPAN
></DIV
><DIV CLASS="apropos"
><DIV CLASS="apropos-io"
><A HREF="f_symbol-value.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_remprop.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="get"
></SPAN
><B
>get</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
>get</B
> <SPAN CLASS="cmssi"
>symbol</SPAN
> <SPAN CLASS="cmssi"
>indicator</SPAN
> <SPAN CLASS="cmtt"
>&amp;optional</SPAN
> <SPAN CLASS="cmssi"
>default</SPAN
> <SPAN CLASS="arrow"
>&#8594;</SPAN
> <SPAN CLASS="cmssi"
>value</SPAN
></P
><P CLASS="j"
><B
>(setf (get</B
> <SPAN CLASS="cmssi"
>symbol</SPAN
> <SPAN CLASS="cmssi"
>indicator</SPAN
> <SPAN CLASS="cmtt"
>&amp;optional</SPAN
> <SPAN CLASS="cmssi"
>default</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
>. </P
><P CLASS="j"
><VAR CLASS="param"
>indicator</VAR
> &#8212; an <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>default</VAR
> &#8212; an <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</EM
></A
>. The default is <SPAN CLASS="misc"
><B
>nil</B
></SPAN
>. </P
><P CLASS="j"
><VAR CLASS="param"
>value</VAR
> &#8212; if the indicated property exists, the <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</EM
></A
> that is its <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>value</EM
></A
>; otherwise, the specified <VAR CLASS="param"
>default</VAR
>. </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_get.html" CLASS="funref"
><B
>get</B
></A
> finds a <A HREF="26_1_Glossary.html#property"
><EM CLASS="term"
>property</EM
></A
> on the <A HREF="26_1_Glossary.html#property_list"
><EM CLASS="term"
>property list</EM
></A
><SPAN CLASS="meaning"
><SUB CLASS="sub"
><SPAN CLASS="cmr"
>2</SPAN
></SUB
></SPAN
> of <VAR CLASS="param"
>symbol</VAR
> whose <A HREF="26_1_Glossary.html#property_indicator"
><EM CLASS="term"
>property indicator</EM
></A
> is <A HREF="26_1_Glossary.html#identical"
><EM CLASS="term"
>identical</EM
></A
> to <VAR CLASS="param"
>indicator</VAR
>, and returns its corresponding <A HREF="26_1_Glossary.html#property_value"
><EM CLASS="term"
>property value</EM
></A
>. If there are multiple <EM CLASS="term"
>properties</EM
><SPAN CLASS="meaning"
><SUB CLASS="sub"
><SPAN CLASS="cmr"
>1</SPAN
></SUB
></SPAN
> with that <A HREF="26_1_Glossary.html#property_indicator"
><EM CLASS="term"
>property indicator</EM
></A
>, <A HREF="f_get.html" CLASS="funref"
><B
>get</B
></A
> uses the first such <A HREF="26_1_Glossary.html#property"
><EM CLASS="term"
>property</EM
></A
>. If there is no <A HREF="26_1_Glossary.html#property"
><EM CLASS="term"
>property</EM
></A
> with that <A HREF="26_1_Glossary.html#property_indicator"
><EM CLASS="term"
>property indicator</EM
></A
>, <VAR CLASS="param"
>default</VAR
> is returned. </P
><P CLASS="j"
><A HREF="f_setf.html" CLASS="macref"
><B
>setf</B
></A
> of <A HREF="f_get.html" CLASS="funref"
><B
>get</B
></A
> may be used to associate a new <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</EM
></A
> with an existing indicator already on the <VAR CLASS="param"
>symbol</VAR
>&#8217;s <A HREF="26_1_Glossary.html#property_list"
><EM CLASS="term"
>property list</EM
></A
>, or to create a new assocation if none exists. If there are multiple <EM CLASS="term"
>properties</EM
><SPAN CLASS="meaning"
><SUB CLASS="sub"
><SPAN CLASS="cmr"
>1</SPAN
></SUB
></SPAN
> with that <A HREF="26_1_Glossary.html#property_indicator"
><EM CLASS="term"
>property indicator</EM
></A
>, <A HREF="f_setf.html" CLASS="macref"
><B
>setf</B
></A
> of <A HREF="f_get.html" CLASS="funref"
><B
>get</B
></A
> associates the <VAR CLASS="param"
>new-value</VAR
> with the first such <A HREF="26_1_Glossary.html#property"
><EM CLASS="term"
>property</EM
></A
>. When a <A HREF="f_get.html" CLASS="funref"
><B
>get</B
></A
> <A HREF="26_1_Glossary.html#form"
><EM CLASS="term"
>form</EM
></A
> is used as a <A HREF="f_setf.html" CLASS="macref"
><B
>setf</B
></A
> <VAR CLASS="param"
>place</VAR
>, any <VAR CLASS="param"
>default</VAR
> which is supplied is evaluated according to normal left-to-right evaluation rules, but its <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>value</EM
></A
> is ignored.</P
></DD
><DT
><B
>Examples</B
></DT
><DD
><PRE CLASS="screen"
> (defun make-person (first-name last-name)
(let ((person (gensym "PERSON")))
(setf (get person 'first-name) first-name)
(setf (get person 'last-name) last-name)
person)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> MAKE-PERSON
(defvar *john* (make-person "John" "Dow")) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> *JOHN*
*john* <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> #:PERSON4603
(defvar *sally* (make-person "Sally" "Jones")) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> *SALLY*
(get *john* 'first-name) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> "John"
(get *sally* 'last-name) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> "Jones"
(defun marry (man woman married-name)
(setf (get man 'wife) woman)
(setf (get woman 'husband) man)
(setf (get man 'last-name) married-name)
(setf (get woman 'last-name) married-name)
married-name) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> MARRY
(marry *john* *sally* "Dow-Jones") <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> "Dow-Jones"
(get *john* 'last-name) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> "Dow-Jones"
(get (get *john* 'wife) 'first-name) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> "Sally"
(symbol-plist *john*)
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> (WIFE #:PERSON4604 LAST-NAME "Dow-Jones" FIRST-NAME "John")
(defmacro age (person &amp;optional (default ''thirty-something))
`(get ,person 'age ,default)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> AGE
(age *john*) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> THIRTY-SOMETHING
(age *john* 20) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 20
(setf (age *john*) 25) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 25
(age *john*) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 25
(age *john* 20) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 25</PRE
></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
></DD
><DT
><B
>See Also</B
></DT
><DD
><P CLASS="j"
><A HREF="f_getf.html" CLASS="funref"
><B
>getf</B
></A
>, <A HREF="f_symbol-plist.html" CLASS="funref"
><B
>symbol-plist</B
></A
>, <A HREF="f_remprop.html" CLASS="funref"
><B
>remprop</B
></A
></P
></DD
><DT
><B
>Notes</B
></DT
><DD
><PRE CLASS="screen"
>(get x y) <SPAN CLASS="cmsy"
><SPAN STYLE="font-size:16px;vertical-align:-2px"
>&#8801;</SPAN
></SPAN
> (getf (symbol-plist x) y)</PRE
><P CLASS="j"
><A HREF="26_1_Glossary.html#number"
><EM CLASS="term"
>Numbers</EM
></A
> and <A HREF="26_1_Glossary.html#character"
><EM CLASS="term"
>characters</EM
></A
> are not recommended for use as <VAR CLASS="param"
>indicators</VAR
> in portable code since <A HREF="f_get.html" CLASS="funref"
><B
>get</B
></A
> tests with <A HREF="f_eq.html" CLASS="funref"
><B
>eq</B
></A
> rather than <A HREF="f_eql.html" CLASS="funref"
><B
>eql</B
></A
>, and consequently the effect of using such <VAR CLASS="param"
>indicators</VAR
> is <A HREF="26_1_Glossary.html#implementation-dependent"
><EM CLASS="term"
>implementation-dependent</EM
></A
>. </P
><P CLASS="j"
>There is no way using <A HREF="f_get.html" CLASS="funref"
><B
>get</B
></A
> to distinguish an absent property from one whose value is <VAR CLASS="param"
>default</VAR
>. However, see <A HREF="f_get-properties.html" CLASS="funref"
><B
>get-properties</B
></A
>.</P
></DD
></DL
></DIV
></DIV
><DIV CLASS="footer"
><DIV CLASS="btmnav"
><A HREF="f_symbol-value.html" CLASS="prev"
>&#8592;</A
><A HREF="f_remprop.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
>