17.05.2015 Views

zl:1 - FTP

zl:1 - FTP

zl:1 - FTP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

defstruct 154<br />

The body forms can be written as if the variables in storing-function-or-args<br />

were bound to subforms of the call on access-fn and the store-variables were<br />

bound to the second subform of setf. However, this is not actually the<br />

case. During the evaluation of the body forms, these variables are bound<br />

to names of temporary variables, generated as if by gensym or gentemp,<br />

that will be bound by the expansion of setf to the values of those subforms.<br />

This binding permits the body forms to be writeen without regard for order<br />

of evaluation. defsetf arranges for the temporary variables to be optimized<br />

out of the final results in cases where that is possible. In other words, an<br />

attempt is made by defsetf to generate the best code possible.<br />

Note that the code generated by the body forms must include provision for<br />

returning the correct value (the value of store-variables). This is handled<br />

by the body forms rather than by defsetf because in many cases this value<br />

can be returned at no extra cost, by calling a function that simultaneously<br />

stores into the generalized variable and returns the correct value.<br />

Here is an example of the complex form of defsetf.<br />

,<br />

I -<br />

(defsetf subseq (sequence start &optional end) (new-sequence)<br />

'(progn (replace ,sequence ,new-sequence<br />

:start1 ,start :end1 ,end)<br />

,new-sequence»<br />

For even more complex operations on setf: See the macro<br />

define-setf-method, page 141.<br />

defstruct options &body items Macro<br />

defstruct defines a record-structure data type. A call to defstruct looks<br />

like:<br />

(defstruct (name option-l option-2 ... )<br />

slot-description-l<br />

slot-description-2<br />

... )<br />

name must be a symbol; it is the name of the structure. It is given a<br />

si:defstruct-description property that describes the attributes and elements<br />

of the structure; this is intended to be used by programs that examine<br />

other Lisp programs and that want to display the contents of structures in<br />

a helpful way. name is used for other things; for more information: See<br />

the section "Named Structures" in Symbolics Common Lisp: Language Concepts.<br />

Because evaluation of a defstruct form causes many functions and macros<br />

to be defined, you must take care not to define the same name with two

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!