98 lines
3 KiB
HTML
98 lines
3 KiB
HTML
|
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
|
||
|
<!Originally converted to HTML using LaTeX2HTML 95 (Thu Jan 19 1995) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
|
||
|
<HEAD>
|
||
|
<TITLE> setf (MACRO)</TITLE>
|
||
|
</HEAD>
|
||
|
<BODY>
|
||
|
<meta name="description" value=" setf (MACRO)">
|
||
|
<meta name="keywords" value="lp">
|
||
|
<meta name="resource-type" value="document">
|
||
|
<meta name="distribution" value="global">
|
||
|
<P>
|
||
|
<BR> <HR>
|
||
|
<A HREF="node114.html"><IMG ALIGN=BOTTOM ALT="next" SRC="next_motif.gif"></A>
|
||
|
<A HREF="node72.html"><IMG ALIGN=BOTTOM ALT="up" SRC="up_motif.gif"></A>
|
||
|
<A HREF="node112.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif"></A> <BR>
|
||
|
<A HREF="lp.html"><B>Contents</B></A>
|
||
|
<B> Next:</B>
|
||
|
<A HREF="node114.html"> symbolp (PREDICATE)</A>
|
||
|
<B>Up:</B>
|
||
|
<A HREF="node72.html"> Appendix: Selected Lisp </A>
|
||
|
<B> Previous:</B>
|
||
|
<A HREF="node112.html"> secondthird, etc. </A>
|
||
|
<BR> <HR> <P>
|
||
|
<H1> setf (MACRO)</H1>
|
||
|
<P>
|
||
|
<b> Format:</b>
|
||
|
<BLOCKQUOTE>
|
||
|
<PRE>(setf <place1> <val1>
|
||
|
<place2> <val2>
|
||
|
.
|
||
|
.
|
||
|
<placeN> <valN> )
|
||
|
</PRE>
|
||
|
</BLOCKQUOTE>
|
||
|
<P>
|
||
|
<b> Required arguments:</b> none
|
||
|
<P>
|
||
|
<b> Optional arguments:</b> any even number of arguments
|
||
|
<P>
|
||
|
<tt> <place> </tt>: either (i) the name of a variable, or (ii) an expression referring to part of a larger structure (e.g. a list, property list, structure, or array).
|
||
|
<tt> <val> </tt>: any Lisp expression.
|
||
|
<P>
|
||
|
setf assigns the result of evaluating <tt> <val> </tt> to the location
|
||
|
specified in the immediately preceding <tt> <place> </tt>. It returns the
|
||
|
result of evaluating the last <tt> <val> </tt>. If no <tt> <place> -<val> </tt>
|
||
|
pairs are specified, setf returns nil. setf is used, among other
|
||
|
things, to assign values to variables, change parts of list structures,
|
||
|
and to manage property lists and structures. Examples of all these uses
|
||
|
are given in the chapters of this book. Other uses, too numerous to document
|
||
|
here, can be found in Steele.
|
||
|
<P>
|
||
|
<b> Examples:</b> (see all chapters for further examples)
|
||
|
<P>
|
||
|
<BLOCKQUOTE>
|
||
|
<PRE>> (setf crew '(picard riker worf crusher))
|
||
|
(PICARD RIKER WORF CRUSHER)
|
||
|
|
||
|
> (setf (first crew) (list 'captain (first crew))
|
||
|
(second crew) (list 'commander (second crew))
|
||
|
(third crew) (list 'lieutenant (third crew))
|
||
|
(fourth crew) (list 'ensign (fourth crew)))
|
||
|
(ENSIGN CRUSHER)
|
||
|
|
||
|
> crew
|
||
|
((CAPTAIN PICARD) (COMMANDER RIKER) (LIEUTENANT WORF)
|
||
|
(ENSIGN CRUSHER))
|
||
|
|
||
|
> (setf (get 'picard 'rank) 'captain)
|
||
|
CAPTAIN
|
||
|
|
||
|
> (get 'picard 'rank)
|
||
|
CAPTAIN
|
||
|
|
||
|
> (defstruct starship crew captain)
|
||
|
STARSHIP
|
||
|
|
||
|
> (setf enterprise (make-starship))
|
||
|
#S(STARSHIP CREW NIL CAPTAIN NIL)
|
||
|
|
||
|
> (setf (starship-crew enterprise) (rest crew)
|
||
|
(starship-captain enterprise) (second (first crew)))
|
||
|
PICARD
|
||
|
|
||
|
> enterprise
|
||
|
#S(STARSHIP CREW
|
||
|
((COMMANDER RIKER) (LIEUTENANT WORF) (ENSIGN CRUSHER))
|
||
|
CAPTAIN PICARD)
|
||
|
</PRE>
|
||
|
</BLOCKQUOTE>
|
||
|
<P>
|
||
|
<BR> <HR>
|
||
|
<P>
|
||
|
<ADDRESS>
|
||
|
<I>© Colin Allen & Maneesh Dhagat <BR>
|
||
|
March 2007 </I>
|
||
|
</ADDRESS>
|
||
|
</BODY>
|