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

579 lines
No EOL
11 KiB
HTML

<!DOCTYPE HTML>
<HTML LANG="en-us"
><HEAD
><TITLE
>getf | Common Lisp Nova Spec</TITLE
><META CHARSET="US-ASCII"
><LINK REL="canonical" HREF="f_getf.html"
><LINK REL="next" HREF="f_remf.html" TYPE="text/html" TITLE="remf"
><LINK REL="prev" HREF="f_get-properties.html" TYPE="text/html" TITLE="get-properties"
><LINK REL="up" HREF="14_2_Conses_Dictionary.html" TYPE="text/html" TITLE="14.2 Conses 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="14_Conses.html"
>14. Conses</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="14_2_Conses_Dictionary.html"
>14.2 Conses Dictionary</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="f_getf.html"
>getf</A
></SPAN
></DIV
><DIV CLASS="apropos"
><DIV CLASS="apropos-io"
><A HREF="f_get-properties.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_remf.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="getf"
></SPAN
><B
>getf</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
>getf</B
> <SPAN CLASS="cmssi"
>plist</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 (getf</B
> <SPAN CLASS="cmssi"
>place</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"
>plist</VAR
> &#8212; a <A HREF="26_1_Glossary.html#property_list"
><EM CLASS="term"
>property list</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
>, the <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>value</EM
></A
> of which is a <A HREF="26_1_Glossary.html#property_list"
><EM CLASS="term"
>property list</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; an <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</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_getf.html" CLASS="funref"
><B
>getf</B
></A
> finds a <A HREF="26_1_Glossary.html#property"
><EM CLASS="term"
>property</EM
></A
> on the <VAR CLASS="param"
>plist</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_getf.html" CLASS="funref"
><B
>getf</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_getf.html" CLASS="funref"
><B
>getf</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 in the <A HREF="26_1_Glossary.html#property_list"
><EM CLASS="term"
>property list</EM
></A
> held by <VAR CLASS="param"
>place</VAR
>, 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_getf.html" CLASS="funref"
><B
>getf</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_getf.html" CLASS="funref"
><B
>getf</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
><P CLASS="j"
><A HREF="f_setf.html" CLASS="macref"
><B
>setf</B
></A
> of <A HREF="f_getf.html" CLASS="funref"
><B
>getf</B
></A
> is permitted to either <A HREF="26_1_Glossary.html#write"
><EM CLASS="term"
>write</EM
></A
> the <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>value</EM
></A
> of <VAR CLASS="param"
>place</VAR
> itself, or modify of any part, <A HREF="26_1_Glossary.html#car"
><EM CLASS="term"
>car</EM
></A
> or <A HREF="26_1_Glossary.html#cdr"
><EM CLASS="term"
>cdr</EM
></A
>, of the <A HREF="26_1_Glossary.html#list_structure"
><EM CLASS="term"
>list structure</EM
></A
> held by <VAR CLASS="param"
>place</VAR
>.</P
></DD
><DT
><B
>Examples</B
></DT
><DD
><PRE CLASS="screen"
> (setq x '()) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> NIL
(getf x 'prop1) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> NIL
(getf x 'prop1 7) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 7
(getf x 'prop1) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> NIL
(setf (getf x 'prop1) 'val1) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> VAL1
(eq (getf x 'prop1) 'val1) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> <A HREF="26_1_Glossary.html#true"
><EM CLASS="term"
>true</EM
></A
>
(getf x 'prop1) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> VAL1
(getf x 'prop1 7) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> VAL1
x <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> (PROP1 VAL1)
;; Examples of implementation variation permitted.
(setq foo (list 'a 'b 'c 'd 'e 'f)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> (A B C D E F)
(setq bar (cddr foo)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> (C D E F)
(remf foo 'c) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> <A HREF="26_1_Glossary.html#true"
><EM CLASS="term"
>true</EM
></A
>
foo <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> (A B E F)
bar
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> (C D E F)
<SPAN CLASS="sp"
><SPAN CLASS="arrow withabove"
><SPAN CLASS="above"
>or </SPAN
>&#8594;</SPAN
></SPAN
> (C)
<SPAN CLASS="sp"
><SPAN CLASS="arrow withabove"
><SPAN CLASS="above"
>or </SPAN
>&#8594;</SPAN
></SPAN
> (NIL)
<SPAN CLASS="sp"
><SPAN CLASS="arrow withabove"
><SPAN CLASS="above"
>or </SPAN
>&#8594;</SPAN
></SPAN
> (C NIL)
<SPAN CLASS="sp"
><SPAN CLASS="arrow withabove"
><SPAN CLASS="above"
>or </SPAN
>&#8594;</SPAN
></SPAN
> (C D)</PRE
></DD
><DT
><B
>See Also</B
></DT
><DD
><P CLASS="j"
><A HREF="f_get.html" CLASS="funref"
><B
>get</B
></A
>, <A HREF="f_get-properties.html" CLASS="funref"
><B
>get-properties</B
></A
>, <A HREF="f_setf.html" CLASS="macref"
><B
>setf</B
></A
>, <A HREF="5_1_Generalized_Reference.html#sec_5_1_2_2" CLASS="secref"
><SPAN CLASS="cmr"
>Section</SPAN
> <SPAN CLASS="cmr"
>5.1.2.2</SPAN
> <SPAN CLASS="cmr"
>(Function</SPAN
> <SPAN CLASS="cmr"
>Call</SPAN
> <SPAN CLASS="cmr"
>Forms</SPAN
> <SPAN CLASS="cmr"
>as</SPAN
> <SPAN CLASS="cmr"
>Places)</SPAN
></A
></P
></DD
><DT
><B
>Notes</B
></DT
><DD
><P CLASS="j"
>There is no way (using <A HREF="f_getf.html" CLASS="funref"
><B
>getf</B
></A
>) to distinguish an absent property from one whose value is <VAR CLASS="param"
>default</VAR
>; but see <A HREF="f_get-properties.html" CLASS="funref"
><B
>get-properties</B
></A
>. </P
><P CLASS="j"
>Note that while supplying a <EM CLASS="term"
>default</EM
> argument to <A HREF="f_getf.html" CLASS="funref"
><B
>getf</B
></A
> in a <A HREF="f_setf.html" CLASS="macref"
><B
>setf</B
></A
> situation is sometimes not very interesting, it is still important because some macros, such as <A HREF="f_push.html" CLASS="macref"
><B
>push</B
></A
> and <A HREF="f_incf.html" CLASS="macref"
><B
>incf</B
></A
>, require a <VAR CLASS="param"
>place</VAR
> argument which data is both <A HREF="26_1_Glossary.html#read"
><EM CLASS="term"
>read</EM
></A
> from and <EM CLASS="term"
>written</EM
> to. In such a context, if a <EM CLASS="term"
>default</EM
> argument is to be supplied for the <A HREF="26_1_Glossary.html#read"
><EM CLASS="term"
>read</EM
></A
> situation, it must be syntactically valid for the <A HREF="26_1_Glossary.html#write"
><EM CLASS="term"
>write</EM
></A
> situation as well. For example,</P
><PRE CLASS="screen"
>(let ((plist '()))
(incf (getf plist 'count 0))
plist) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> (COUNT 1)</PRE
></DD
></DL
></DIV
></DIV
><DIV CLASS="footer"
><DIV CLASS="btmnav"
><A HREF="f_get-properties.html" CLASS="prev"
>&#8592;</A
><A HREF="f_remf.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
>