1
0
Fork 0
cl-sites/HyperSpec-7-0/HyperSpec/Body/05_aa.htm
2024-04-01 10:24:07 +02:00

57 lines
7.5 KiB
HTML

<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
<HTML>
<HEAD>
<TITLE>CLHS: Section 5.1.1</TITLE>
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
<LINK REL=TOP HREF="../Front/index.htm">
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
<LINK REL=PREV HREF="05_a.htm">
<LINK REL=UP HREF="05_a.htm">
<LINK REL=NEXT HREF="05_aaa.htm">
</HEAD>
<BODY>
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="05_a.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="05_a.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="05_aaa.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>
5.1.1 Overview of Places and Generalized Reference</H2> <P>
A <A REL=DEFINITION HREF="26_glo_g.htm#generalized_reference"><I>generalized reference</I></A> is the use of a <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A>, sometimes called a <A REL=DEFINITION HREF="26_glo_p.htm#place"><I>place</I></A>, as if it were a <A REL=DEFINITION HREF="26_glo_v.htm#variable"><I>variable</I></A> that could be read and written. The <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>value</I></A> of a <A REL=DEFINITION HREF="26_glo_p.htm#place"><I>place</I></A> is the <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>object</I></A> to which the <A REL=DEFINITION HREF="26_glo_p.htm#place"><I>place</I></A> <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> evaluates. The <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>value</I></A> of a <A REL=DEFINITION HREF="26_glo_p.htm#place"><I>place</I></A> can be changed by using <A REL=DEFINITION HREF="m_setf_.htm#setf"><B>setf</B></A>. The concept of binding a <A REL=DEFINITION HREF="26_glo_p.htm#place"><I>place</I></A> is not defined in Common Lisp, but an <A REL=DEFINITION HREF="26_glo_i.htm#implementation"><I>implementation</I></A> is permitted to extend the language by defining this concept. <P>
The next figure contains examples of the use of <A REL=DEFINITION HREF="m_setf_.htm#setf"><B>setf</B></A>. Note that the values returned by evaluating the <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>forms</I></A> in column two are not necessarily the same as those obtained by evaluating the <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>forms</I></A> in column three. In general, the exact <A REL=DEFINITION HREF="26_glo_m.htm#macro_expansion"><I>macro expansion</I></A> of a <A REL=DEFINITION HREF="m_setf_.htm#setf"><B>setf</B></A> <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> is not guaranteed and can even be <A REL=DEFINITION HREF="26_glo_i.htm#implementation-dependent"><I>implementation-dependent</I></A>; all that is guaranteed is that the expansion is an update form that works for that particular <A REL=DEFINITION HREF="26_glo_i.htm#implementation"><I>implementation</I></A>, that the left-to-right evaluation of <A REL=DEFINITION HREF="26_glo_s.htm#subform"><I>subforms</I></A> is preserved, and that the ultimate result of evaluating <A REL=DEFINITION HREF="m_setf_.htm#setf"><B>setf</B></A> is the value or values being stored. <P>
<PRE>
Access function Update Function Update using <A REL=DEFINITION HREF="m_setf_.htm#setf">setf</A>
x (setq x datum) (setf x datum)
(car x) (rplaca x datum) (setf (car x) datum)
(symbol-value x) (set x datum) (setf (symbol-value x) datum)
</PRE>
<P><B>Figure 5-1. Examples of setf</B> <P>
The next figure shows <A REL=DEFINITION HREF="26_glo_o.htm#operator"><I>operators</I></A> relating to <A REL=DEFINITION HREF="26_glo_p.htm#place"><I>places</I></A> and <A REL=DEFINITION HREF="26_glo_g.htm#generalized_reference"><I>generalized reference</I></A>. <P>
<P>
<PRE>
<A REL=DEFINITION HREF="m_assert.htm#assert">assert</A> <A REL=DEFINITION HREF="m_defset.htm#defsetf">defsetf</A> <A REL=DEFINITION HREF="m_push.htm#push">push</A>
<A REL=DEFINITION HREF="m_case_.htm#ccase">ccase</A> <A REL=DEFINITION HREF="f_get_se.htm#get-setf-expansion">get-setf-expansion</A> <A REL=DEFINITION HREF="m_remf.htm#remf">remf</A>
<A REL=DEFINITION HREF="m_tpcase.htm#ctypecase">ctypecase</A> <A REL=DEFINITION HREF="f_getf.htm#getf">getf</A> <A REL=DEFINITION HREF="m_rotate.htm#rotatef">rotatef</A>
<A REL=DEFINITION HREF="m_incf_.htm#decf">decf</A> <A REL=DEFINITION HREF="m_incf_.htm#incf">incf</A> <A REL=DEFINITION HREF="a_setf.htm#setf">setf</A>
<A REL=DEFINITION HREF="m_defi_2.htm#define-modify-macro">define-modify-macro</A> <A REL=DEFINITION HREF="m_pop.htm#pop">pop</A> <A REL=DEFINITION HREF="m_shiftf.htm#shiftf">shiftf</A>
<A REL=DEFINITION HREF="m_defi_3.htm#define-setf-expander">define-setf-expander</A> <A REL=DEFINITION HREF="m_setf_.htm#psetf">psetf</A>
</PRE>
<P><B>Figure 5-2. Operators relating to places and generalized reference.</B> <P>
<P>
Some of the <A REL=DEFINITION HREF="26_glo_o.htm#operator"><I>operators</I></A> above manipulate <A REL=DEFINITION HREF="26_glo_p.htm#place"><I>places</I></A> and some manipulate <A REL=DEFINITION HREF="26_glo_s.htm#setf_expander"><I>setf expanders</I></A>. A <A REL=DEFINITION HREF="26_glo_s.htm#setf_expansion"><I>setf expansion</I></A> can be derived from any <A REL=DEFINITION HREF="26_glo_p.htm#place"><I>place</I></A>. New <A REL=DEFINITION HREF="26_glo_s.htm#setf_expander"><I>setf expanders</I></A> can be defined by using <A REL=DEFINITION HREF="m_defset.htm#defsetf"><B>defsetf</B></A> and <A REL=DEFINITION HREF="m_defi_3.htm#define-setf-expander"><B>define-setf-expander</B></A>. <P>
<A REL=CHILD HREF="05_aaa.htm"><H2>
5.1.1.1 Evaluation of Subforms to Places</H2></A><P> <P>
<A REL=CHILD HREF="05_aab.htm"><H2>
5.1.1.2 Setf Expansions</H2></A><P><P><HR>The following <A REL=META HREF="../Front/X3J13Iss.htm">X3J13 cleanup issues</A>, <I>not part of the specification</I>, apply to this section:<P><UL><LI> <A REL=CHILD HREF="../Issues/iss280.htm">PUSH-EVALUATION-ORDER:ITEM-FIRST</A><LI> <A REL=CHILD HREF="../Issues/iss308.htm">SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS</A><P></UL><HR>
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
</BODY>
</HTML>