107 lines
16 KiB
HTML
107 lines
16 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.2.2</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_aba.htm">
|
|
<LINK REL=UP HREF="05_ab.htm">
|
|
<LINK REL=NEXT HREF="05_abc.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_aba.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="05_ab.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="05_abc.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
<H2>
|
|
5.1.2.2 Function Call Forms as Places</H2> <P>
|
|
A <A REL=DEFINITION HREF="26_glo_f.htm#function_form"><I>function form</I></A> can be used as a <A REL=DEFINITION HREF="26_glo_p.htm#place"><I>place</I></A> if it falls into one of the following categories: <P>
|
|
<P><DL><P>
|
|
<DT>* A function call form whose first element is the name of any one of the functions in the next figure. <P><DD>
|
|
<P>
|
|
<PRE>
|
|
<A REL=DEFINITION HREF="f_aref.htm#aref">aref</A> <A REL=DEFINITION HREF="f_car_c.htm#cdadr">cdadr</A> <A REL=DEFINITION HREF="f_get.htm#get">get</A>
|
|
<A REL=DEFINITION HREF="a_bit.htm#bit">bit</A> <A REL=DEFINITION HREF="f_car_c.htm#cdar">cdar</A> <A REL=DEFINITION HREF="f_gethas.htm#gethash">gethash</A>
|
|
<A REL=DEFINITION HREF="f_car_c.htm#caaaar">caaaar</A> <A REL=DEFINITION HREF="f_car_c.htm#cddaar">cddaar</A> <A REL=DEFINITION HREF="f_logica.htm#logical-pathname-translations">logical-pathname-translations</A>
|
|
<A REL=DEFINITION HREF="f_car_c.htm#caaadr">caaadr</A> <A REL=DEFINITION HREF="f_car_c.htm#cddadr">cddadr</A> <A REL=DEFINITION HREF="f_macro_.htm#macro-function">macro-function</A>
|
|
<A REL=DEFINITION HREF="f_car_c.htm#caaar">caaar</A> <A REL=DEFINITION HREF="f_car_c.htm#cddar">cddar</A> <A REL=DEFINITION HREF="f_firstc.htm#ninth">ninth</A>
|
|
<A REL=DEFINITION HREF="f_car_c.htm#caadar">caadar</A> <A REL=DEFINITION HREF="f_car_c.htm#cdddar">cdddar</A> <A REL=DEFINITION HREF="f_nth.htm#nth">nth</A>
|
|
<A REL=DEFINITION HREF="f_car_c.htm#caaddr">caaddr</A> <A REL=DEFINITION HREF="f_car_c.htm#cddddr">cddddr</A> <A REL=DEFINITION HREF="f_rdtabl.htm#readtable-case">readtable-case</A>
|
|
<A REL=DEFINITION HREF="f_car_c.htm#caadr">caadr</A> <A REL=DEFINITION HREF="f_car_c.htm#cdddr">cdddr</A> <A REL=DEFINITION HREF="f_rest.htm#rest">rest</A>
|
|
<A REL=DEFINITION HREF="f_car_c.htm#caar">caar</A> <A REL=DEFINITION HREF="f_car_c.htm#cddr">cddr</A> <A REL=DEFINITION HREF="f_row_ma.htm#row-major-aref">row-major-aref</A>
|
|
<A REL=DEFINITION HREF="f_car_c.htm#cadaar">cadaar</A> <A REL=DEFINITION HREF="f_car_c.htm#cdr">cdr</A> <A REL=DEFINITION HREF="f_bt_sb.htm#sbit">sbit</A>
|
|
<A REL=DEFINITION HREF="f_car_c.htm#cadadr">cadadr</A> <A REL=DEFINITION HREF="f_char_.htm#char">char</A> <A REL=DEFINITION HREF="f_char_.htm#schar">schar</A>
|
|
<A REL=DEFINITION HREF="f_car_c.htm#cadar">cadar</A> <A REL=DEFINITION HREF="f_class_.htm#class-name">class-name</A> <A REL=DEFINITION HREF="f_firstc.htm#second">second</A>
|
|
<A REL=DEFINITION HREF="f_car_c.htm#caddar">caddar</A> <A REL=DEFINITION HREF="f_cmp_ma.htm#compiler-macro-function">compiler-macro-function</A> <A REL=DEFINITION HREF="f_firstc.htm#seventh">seventh</A>
|
|
<A REL=DEFINITION HREF="f_car_c.htm#cadddr">cadddr</A> <A REL=DEFINITION HREF="f_docume.htm#documentation">documentation</A> <A REL=DEFINITION HREF="f_firstc.htm#sixth">sixth</A>
|
|
<A REL=DEFINITION HREF="f_car_c.htm#caddr">caddr</A> <A REL=DEFINITION HREF="f_firstc.htm#eighth">eighth</A> <A REL=DEFINITION HREF="f_slt_va.htm#slot-value">slot-value</A>
|
|
<A REL=DEFINITION HREF="f_car_c.htm#cadr">cadr</A> <A REL=DEFINITION HREF="f_elt.htm#elt">elt</A> <A REL=DEFINITION HREF="f_subseq.htm#subseq">subseq</A>
|
|
<A REL=DEFINITION HREF="f_car_c.htm#car">car</A> <A REL=DEFINITION HREF="f_fdefin.htm#fdefinition">fdefinition</A> <A REL=DEFINITION HREF="f_svref.htm#svref">svref</A>
|
|
<A REL=DEFINITION HREF="f_car_c.htm#cdaaar">cdaaar</A> <A REL=DEFINITION HREF="f_firstc.htm#fifth">fifth</A> <A REL=DEFINITION HREF="f_symb_1.htm#symbol-function">symbol-function</A>
|
|
<A REL=DEFINITION HREF="f_car_c.htm#cdaadr">cdaadr</A> <A REL=DEFINITION HREF="f_fill_p.htm#fill-pointer">fill-pointer</A> <A REL=DEFINITION HREF="f_symb_4.htm#symbol-plist">symbol-plist</A>
|
|
<A REL=DEFINITION HREF="f_car_c.htm#cdaar">cdaar</A> <A REL=DEFINITION HREF="f_find_c.htm#find-class">find-class</A> <A REL=DEFINITION HREF="f_symb_5.htm#symbol-value">symbol-value</A>
|
|
<A REL=DEFINITION HREF="f_car_c.htm#cdadar">cdadar</A> <A REL=DEFINITION HREF="f_firstc.htm#first">first</A> <A REL=DEFINITION HREF="f_firstc.htm#tenth">tenth</A>
|
|
<A REL=DEFINITION HREF="f_car_c.htm#cdaddr">cdaddr</A> <A REL=DEFINITION HREF="f_firstc.htm#fourth">fourth</A> <A REL=DEFINITION HREF="f_firstc.htm#third">third</A>
|
|
</PRE>
|
|
<P><B>Figure 5-7. Functions that setf can be used with---1</B> <P>
|
|
In the case of <A REL=DEFINITION HREF="f_subseq.htm#subseq"><B>subseq</B></A>, the replacement value must be a <A REL=DEFINITION HREF="26_glo_s.htm#sequence"><I>sequence</I></A> whose elements might be contained by the sequence argument to <A REL=DEFINITION HREF="f_subseq.htm#subseq"><B>subseq</B></A>, but does not have to be a <A REL=DEFINITION HREF="26_glo_s.htm#sequence"><I>sequence</I></A> of the same <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> as the <A REL=DEFINITION HREF="26_glo_s.htm#sequence"><I>sequence</I></A> of which the subsequence is specified. If the length of the replacement value does not equal the length of the subsequence to be replaced, then the shorter length determines the number of elements to be stored, as for <A REL=DEFINITION HREF="f_replac.htm#replace"><B>replace</B></A>. <P>
|
|
<DT>* A function call form whose first element is the name of a selector function constructed by <A REL=DEFINITION HREF="m_defstr.htm#defstruct"><B>defstruct</B></A>. The function name must refer to the global function definition, rather than a locally defined <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A>. <P><DD>
|
|
<DT>* A function call form whose first element is the name of any one of the functions in the next figure, provided that the supplied argument to that function is in turn a <A REL=DEFINITION HREF="26_glo_p.htm#place"><I>place</I></A> form; in this case the new <A REL=DEFINITION HREF="26_glo_p.htm#place"><I>place</I></A> has stored back into it the result of applying the supplied ``update'' function. <P><DD>
|
|
<PRE>
|
|
Function name Argument that is a place Update function used
|
|
<A REL=DEFINITION HREF="f_ldb.htm#ldb">ldb</A> second <A REL=DEFINITION HREF="f_dpb.htm#dpb">dpb</A>
|
|
<A REL=DEFINITION HREF="f_mask_f.htm#mask-field">mask-field</A> second <A REL=DEFINITION HREF="f_deposi.htm#deposit-field">deposit-field</A>
|
|
<A REL=DEFINITION HREF="f_getf.htm#getf">getf</A> first <A REL=DEFINITION HREF="26_glo_i.htm#implementation-dependent">implementation-dependent</A>
|
|
</PRE>
|
|
<P><B>Figure 5-8. Functions that setf can be used with---2</B> During the <A REL=DEFINITION HREF="m_setf_.htm#setf"><B>setf</B></A> expansion of these <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>forms</I></A>, it is necessary to call <A REL=DEFINITION HREF="f_get_se.htm#get-setf-expansion"><B>get-setf-expansion</B></A> in order to figure out how the inner, nested generalized variable must be treated. <P>
|
|
The information from <A REL=DEFINITION HREF="f_get_se.htm#get-setf-expansion"><B>get-setf-expansion</B></A> is used as follows. <P><DL> <DT><A REL=DEFINITION HREF="f_ldb.htm#ldb"><B>ldb</B></A> <P><DD>
|
|
In a form such as: <P>
|
|
<TT>(setf (ldb </TT><I>byte-spec</I><TT> </TT><I>place-form</I><TT>) </TT><I>value-form</I><TT>)</TT> <P>
|
|
the place referred to by the <I>place-form</I> must always be both <A REL=DEFINITION HREF="26_glo_r.htm#read"><I>read</I></A> and <I>written</I>; note that the update is to the generalized variable specified by <I>place-form</I>, not to any object of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="t_intege.htm#integer"><B>integer</B></A>. <P>
|
|
Thus this <A REL=DEFINITION HREF="m_setf_.htm#setf"><B>setf</B></A> should generate code to do the following: <P>
|
|
<P><DL><DT>1. Evaluate <I>byte-spec</I> (and bind it into a temporary variable). <DD><DT>2. Bind the temporary variables for <I>place-form</I>. <DD><DT>3. Evaluate <I>value-form</I> (and bind its value or values into the store variable). <DD><DT>4. Do the <A REL=DEFINITION HREF="26_glo_r.htm#read"><I>read</I></A> from <I>place-form</I>. <DD><DT>5. Do the <A REL=DEFINITION HREF="26_glo_w.htm#write"><I>write</I></A> into <I>place-form</I> with the given bits of the <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A> fetched in step 4 replaced with the value from step 3. <P><DD></DL>If the evaluation of <I>value-form</I> in step 3 alters what is found in <I>place-form</I>, such as setting different bits of <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A>, then the change of the bits denoted by <I>byte-spec</I> is to that altered <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A>, because step 4 is done after the <I>value-form</I> evaluation. Nevertheless, the evaluations required for <A REL=DEFINITION HREF="26_glo_b.htm#binding"><I>binding</I></A> the temporary variables are done in steps 1 and 2, and thus the expected left-to-right evaluation order is seen. For example: <P>
|
|
<PRE>
|
|
(setq integer #x69) => #x69
|
|
(rotatef (ldb (byte 4 4) integer)
|
|
(ldb (byte 4 0) integer))
|
|
integer => #x96
|
|
;;; This example is trying to swap two independent bit fields
|
|
;;; in an integer. Note that the generalized variable of
|
|
;;; interest here is just the (possibly local) program variable
|
|
;;; integer.
|
|
</PRE>
|
|
</TT> <P>
|
|
<DT><A REL=DEFINITION HREF="f_mask_f.htm#mask-field"><B>mask-field</B></A> <P><DD>
|
|
This case is the same as <A REL=DEFINITION HREF="f_ldb.htm#ldb"><B>ldb</B></A> in all essential aspects. <P>
|
|
<DT><A REL=DEFINITION HREF="f_getf.htm#getf"><B>getf</B></A> <P><DD>
|
|
In a form such as: <P>
|
|
<TT>(setf (getf </TT><I>place-form</I><TT> </TT><I>ind-form</I><TT>) </TT><I>value-form</I><TT>)</TT> <P>
|
|
the place referred to by <I>place-form</I> must always be both <A REL=DEFINITION HREF="26_glo_r.htm#read"><I>read</I></A> and <I>written</I>; note that the update is to the generalized variable specified by <I>place-form</I>, not necessarily to the particular <A REL=DEFINITION HREF="26_glo_l.htm#list"><I>list</I></A> that is the property list in question. <P>
|
|
Thus this <A REL=DEFINITION HREF="m_setf_.htm#setf"><B>setf</B></A> should generate code to do the following: <P><DL><DT>1. Bind the temporary variables for <I>place-form</I>. <DD><DT>2. Evaluate <I>ind-form</I> (and bind it into a temporary variable). <DD><DT>3. Evaluate <I>value-form</I> (and bind its value or values into the store variable). <DD><DT>4. Do the <A REL=DEFINITION HREF="26_glo_r.htm#read"><I>read</I></A> from <I>place-form</I>. <DD><DT>5. Do the <A REL=DEFINITION HREF="26_glo_w.htm#write"><I>write</I></A> into <I>place-form</I> with a possibly-new property list obtained by combining the values from steps 2, 3, and 4. (Note that the phrase ``possibly-new property list'' can mean that the former property list is somehow destructively re-used, or it can mean partial or full copying of it. Since either copying or destructive re-use can occur, the treatment of the resultant value for the possibly-new property list must proceed as if it were a different copy needing to be stored back into the generalized variable.) <P><DD></DL>If the evaluation of <I>value-form</I> in step 3 alters what is found in <I>place-form</I>, such as setting a different named property in the list, then the change of the property denoted by <I>ind-form</I> is to that altered list, because step 4 is done after the <I>value-form</I> evaluation. Nevertheless, the evaluations required for <A REL=DEFINITION HREF="26_glo_b.htm#binding"><I>binding</I></A> the temporary variables are done in steps 1 and 2, and thus the expected left-to-right evaluation order is seen. <P>
|
|
For example: <P>
|
|
<PRE>
|
|
(setq s (setq r (list (list 'a 1 'b 2 'c 3)))) => ((a 1 b 2 c 3))
|
|
(setf (getf (car r) 'b)
|
|
(progn (setq r nil) 6)) => 6
|
|
r => NIL
|
|
s => ((A 1 B 6 C 3))
|
|
;;; Note that the (setq r nil) does not affect the actions of
|
|
;;; the SETF because the value of R had already been saved in
|
|
;;; a temporary variable as part of the step 1. Only the CAR
|
|
;;; of this value will be retrieved, and subsequently modified
|
|
;;; after the value computation.
|
|
</PRE>
|
|
</TT> <P>
|
|
<P></DL><P></DL><P>
|
|
<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/iss309.htm">SETF-MULTIPLE-STORE-VARIABLES:ALLOW</A><LI> <A REL=CHILD HREF="../Issues/iss027.htm">CHARACTER-PROPOSAL:2-1-1</A><LI> <A REL=CHILD HREF="../Issues/iss308.htm">SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS</A><LI> <A REL=CHILD HREF="../Issues/iss312.htm">SETF-SUB-METHODS:DELAYED-ACCESS-STORES</A><LI> <A REL=CHILD HREF="../Issues/iss174.htm">FUNCTION-NAME:LARGE</A><LI> <A REL=CHILD HREF="../Issues/iss009.htm">AREF-1D</A><LI> <A REL=CHILD HREF="../Issues/iss259.htm">PATHNAME-LOGICAL:ADD</A><LI> <A REL=CHILD HREF="../Issues/iss074.htm">CONDITION-ACCESSORS-SETFABLE:NO</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>
|