concept-places.tex 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928
  1. % -*- Mode: TeX -*-
  2. %% Generalized Reference
  3. %% Moon thinks terms "generalized reference" and "place" need to be rationalized throughout.
  4. %% Done! -kmp 16-Jul-93
  5. \beginsubSection{Overview of Places and Generalized Reference}
  6. A \newterm{generalized reference} is the use of a \term{form},
  7. sometimes called a \newterm{place},
  8. as if it were a \term{variable} that could be read and written.
  9. The \term{value} of a \term{place} is
  10. the \term{object} to which the \term{place} \term{form} evaluates.
  11. The \term{value} of a \term{place} can be changed by using \macref{setf}.
  12. The concept of binding a \term{place} is not defined in \clisp,
  13. but an \term{implementation} is permitted to extend the language by defining this concept.
  14. \Thenextfigure\ contains examples of the use of \macref{setf}.
  15. Note that the values returned by evaluating the \term{forms} in column two
  16. are not necessarily the same as those obtained by evaluating the
  17. \term{forms} in column three.
  18. %% 7.2.0 18
  19. In general, the exact \term{macro expansion} of a \macref{setf} \term{form} is not guaranteed
  20. and can even be \term{implementation-dependent};
  21. all that is guaranteed is
  22. that the expansion is an update form that works
  23. for that particular \term{implementation},
  24. that the left-to-right evaluation of \term{subforms} is preserved,
  25. and
  26. %% 7.2.0 19
  27. that the ultimate result of evaluating \macref{setf} is the value
  28. or values being stored.
  29. \tablefigthree{Examples of setf}{Access function}{Update Function}{Update using \macref{setf}}{
  30. \f{x} & \f{(setq x datum)} & \f{(setf x datum)} \cr
  31. \f{(car x)} & \f{(rplaca x datum)} & \f{(setf (car x) datum)} \cr
  32. \f{(symbol-value x)} & \f{(set x datum)} & \f{(setf (symbol-value x) datum)} \cr}
  33. \Thenextfigure\ shows \term{operators} relating to
  34. \term{places} and \term{generalized reference}.
  35. \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  36. \displaythree{Operators relating to places and generalized reference.}{
  37. assert&defsetf&push\cr
  38. ccase&get-setf-expansion&remf\cr
  39. ctypecase&getf&rotatef\cr
  40. decf&incf&setf\cr
  41. define-modify-macro&pop&shiftf\cr
  42. define-setf-expander&psetf&\cr
  43. }
  44. %!!! Should defmethod be here for the sake of SETF methods?? -kmp 8-May-91
  45. \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  46. \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  47. Some of the \term{operators} above manipulate \term{places}
  48. and some manipulate \term{setf expanders}.
  49. %% 7.2.0 57
  50. A \term{setf expansion} can be derived from any \term{place}.
  51. \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  52. %% 7.2.0 20
  53. New \term{setf expanders} can be defined by using \macref{defsetf}
  54. and \macref{define-setf-expander}.
  55. %% Moon thinks this follows from rule 2 below, and asked that it be commented out.
  56. %
  57. % %% 7.2.0 29
  58. % %% 7.2.0 30
  59. % These operators evaluate the \term{subforms} of
  60. % \term{places} exactly as many times as they appear in the source program,
  61. % and exactly in the same order (left-to-right) as they appear in the source.
  62. % \issue{PUSH-EVALUATION-ORDER:ITEM-FIRST}
  63. % %The left-to-right rule does not
  64. % %remove the obligation on writers of \term{macros} and
  65. % %users of
  66. % %\issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  67. % %\macref{define-setf-expander}
  68. % %\endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  69. % %to ensure left-to-right order, however.
  70. % \endissue{PUSH-EVALUATION-ORDER:ITEM-FIRST}
  71. %
  72. % %% 7.2.0 31
  73. % For example, in
  74. %
  75. % {\tt (setf \param{reference} \param{value})}
  76. %
  77. % \param{value}
  78. % will be evaluated after all the \term{subforms} of \param{reference} because
  79. % \param{value} appears to the right of them.
  80. %% 7.2.0 32
  81. %The expansion of these operators must consist of code that follows these
  82. %rules or has the same effect as such code. This is accomplished by
  83. %introducing temporary variables bound to the
  84. %\issue{PUSH-EVALUATION-ORDER:ITEM-FIRST}
  85. %\term{subforms} of the macro call.
  86. %\endissue{PUSH-EVALUATION-ORDER:ITEM-FIRST}
  87. %As an optimization in the implementation,
  88. %temporary variables can be eliminated whenever
  89. %removing them has no effect on the semantics of the program.
  90. %For example, a constant need never be saved in a temporary variable.
  91. %A variable or any \term{form} that does not have side effects need not be
  92. %saved in a temporary variable if it can be proven that its value will
  93. %not change within the scope of the \term{place}.
  94. \issue{PUSH-EVALUATION-ORDER:ITEM-FIRST}
  95. \beginsubsubsection{Evaluation of Subforms to Places}
  96. \DefineSection{GenRefSubFormEval}
  97. The following rules apply to the \term{evaluation} of \term{subforms} in a
  98. \term{place}:
  99. \beginlist
  100. \itemitem{1.}
  101. The evaluation ordering of \term{subforms} within a \term{place}
  102. is determined by the order specified by the second value returned by
  103. \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  104. \funref{get-setf-expansion}.
  105. \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  106. For all \term{places} defined by this specification
  107. %!!! Table??
  108. (\eg \funref{getf}, \funref{ldb}, $\ldots$),
  109. this order of evaluation is left-to-right.
  110. \idxtext{order of evaluation}\idxtext{evaluation order}%
  111. %!!! Barmar: Does the next sentence say the same thing as the one which follows it
  112. % (i.e., the first sentence in the next paragraph)??
  113. When a \term{place} is derived from a macro expansion,
  114. this rule is applied after the macro is expanded to find the appropriate \term{place}.
  115. \term{Places} defined by using \macref{defmacro} or
  116. \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  117. \macref{define-setf-expander}
  118. \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  119. use the evaluation order defined by those definitions.
  120. For example, consider the following:
  121. \code
  122. (defmacro wrong-order (x y) `(getf ,y ,x))
  123. \endcode
  124. This following \term{form} evaluates \f{place2} first and
  125. then \f{place1} because that is the order they are evaluated in
  126. the macro expansion:
  127. \code
  128. (push value (wrong-order place1 place2))
  129. \endcode
  130. \itemitem{2.}
  131. \issue{JUN90-TRIVIAL-ISSUES:4}
  132. For the \term{macros} that manipulate \term{places}
  133. (\macref{push},
  134. \macref{pushnew},
  135. \macref{remf},
  136. \macref{incf},
  137. \macref{decf},
  138. \macref{shiftf},
  139. \macref{rotatef},
  140. \macref{psetf},
  141. \macref{setf},
  142. \macref{pop}, and those defined by \macref{define-modify-macro})
  143. the \term{subforms} of the macro call are evaluated exactly once
  144. in left-to-right order, with the \term{subforms} of the \term{places}
  145. evaluated in the order specified in (1).
  146. \endissue{JUN90-TRIVIAL-ISSUES:4}
  147. \macref{push}, \macref{pushnew}, \macref{remf},
  148. \macref{incf}, \macref{decf}, \macref{shiftf}, \macref{rotatef},
  149. \macref{psetf}, \macref{pop} evaluate all \term{subforms} before modifying
  150. any of the \term{place} locations.
  151. \macref{setf} (in the case when \macref{setf} has more than two arguments)
  152. performs its operation on each pair in sequence. For example, in
  153. \code
  154. (setf place1 value1 place2 value2 ...)
  155. \endcode
  156. the \term{subforms} of \f{place1} and \f{value1} are evaluated, the location
  157. specified by
  158. \f{place1} is modified to contain the value returned by
  159. \f{value1}, and
  160. then the rest of the \macref{setf} form is processed in a like manner.
  161. \itemitem{3.}
  162. For \macref{check-type}, \macref{ctypecase}, and \macref{ccase},
  163. \term{subforms} of the \term{place} are evaluated once as in (1),
  164. but might be evaluated again if the
  165. type check fails in the case of \macref{check-type}
  166. or none of the cases hold in
  167. \macref{ctypecase} and \macref{ccase}.
  168. \itemitem{4.}
  169. For \macref{assert}, the order of evaluation of the generalized
  170. references is not specified.\idxtext{order of evaluation}\idxtext{evaluation order}
  171. % Barmar: There's only one place in \macref{assert}.
  172. % Moon: Not true!
  173. \endlist
  174. Rules 2, 3 and 4 cover all \term{standardized} \term{macros} that manipulate \term{places}.
  175. \beginsubsubsubsection{Examples of Evaluation of Subforms to Places}
  176. \code
  177. (let ((ref2 (list '())))
  178. (push (progn (princ "1") 'ref-1)
  179. (car (progn (princ "2") ref2))))
  180. \OUT 12
  181. \EV (REF1)
  182. (let (x)
  183. (push (setq x (list 'a))
  184. (car (setq x (list 'b))))
  185. x)
  186. \EV (((A) . B))
  187. \endcode
  188. \macref{push} first evaluates {\tt (setq x (list 'a)) \EV\ (a)},
  189. then evaluates {\tt (setq x (list 'b)) \EV\ (b)},
  190. then modifies the \term{car} of this latest value to be {\tt ((a) . b)}.
  191. \endsubsubsubsection%{Examples of Evaluation of Subforms to Places}
  192. \endsubsubsection%{Evaluation of Subforms to Places}
  193. \endissue{PUSH-EVALUATION-ORDER:ITEM-FIRST}
  194. %!!! Uses of "access", "accessing", etc. here are suspect. -kmp 18-Apr-91
  195. \beginsubsubsection{Setf Expansions}
  196. \DefineSection{SetfExpansions}
  197. %% 7.2.0 59
  198. Sometimes it is possible to avoid evaluating \term{subforms} of a
  199. \term{place} multiple times or in the wrong order. A
  200. \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  201. \term{setf expansion}
  202. \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  203. for a given access form can be expressed as an ordered collection of five \term{objects}:
  204. %!!! Andy Latto is concerned about whether "temporaries" mustn't or might
  205. % be proclaimed special. And if they must not, must an implementation check?
  206. % Would some elaboration of what a "temporary" is here be of help? -kmp 5-Dec-91
  207. %% 7.2.0 60
  208. \beginlist
  209. %% 7.2.0 64
  210. \itemitem{\b{List of temporary variables}}
  211. a list of symbols naming temporary variables to be bound
  212. sequentially, as if by \specref{let*}, to \term{values}
  213. resulting from value forms.
  214. \itemitem{\b{List of value forms}}
  215. a list of forms (typically, \term{subforms} of the
  216. \term{place}) which when evaluated
  217. yield the values to which the corresponding temporary
  218. variables should be bound.
  219. %% 7.2.0 61
  220. %% 7.2.0 65
  221. \itemitem{\b{List of store variables}}
  222. a list of symbols naming temporary store variables which are
  223. to hold the new values that will be assigned to the
  224. \term{place}.
  225. %% 7.2.0 62
  226. \itemitem{\b{Storing form}}
  227. a form which can reference both the temporary and the store variables,
  228. and which changes the \term{value} of the \term{place}
  229. and guarantees to return as its values the values of the store variables,
  230. which are the correct values for \macref{setf} to return.
  231. %% 7.2.0 63
  232. \itemitem{\b{Accessing form}}
  233. a \term{form} which can reference the temporary variables,
  234. and which returns the \term{value} of the \term{place}.
  235. \endlist
  236. %% 7.2.0 66
  237. The value returned by the accessing form is
  238. affected by execution of the storing form, but either of these
  239. forms might be evaluated any number of times.
  240. %% 7.2.0 67
  241. %% Redundant with next paragraph.
  242. % The temporary variables and the store variables must be generated
  243. % names (see \funref{gensym} or \funref{gentemp}).
  244. It is possible
  245. to do more than one \macref{setf} in parallel via
  246. \macref{psetf}, \macref{shiftf}, and \macref{rotatef}.
  247. Because of this, the
  248. \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  249. \term{setf expander}
  250. \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  251. must produce new temporary
  252. and store variable names every time. For examples of how to do this,
  253. see \funref{gensym}.
  254. % and \funref{gentemp}.
  255. \issue{SETF-FUNCTIONS-AGAIN:MINIMAL-CHANGES}
  256. For each \term{standardized} accessor function \param{F},
  257. unless it is explicitly documented otherwise,
  258. it is \term{implementation-dependent} whether the ability to
  259. use an \param{F} \term{form} as a \macref{setf} \term{place}
  260. is implemented by a \term{setf expander} or a \term{setf function}.
  261. Also, it follows from this that it is \term{implementation-dependent}
  262. whether the name \f{(setf \param{F})} is \term{fbound}.
  263. \endissue{SETF-FUNCTIONS-AGAIN:MINIMAL-CHANGES}
  264. \beginsubsubsubsection{Examples of Setf Expansions}
  265. \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  266. Examples of the contents of the constituents of \term{setf expansions}
  267. follow.
  268. %% 7.2.0 69
  269. For a variable \param{x}:
  270. \showtwo{Sample Setf Expansion of a Variable}{
  271. \f{()} & ;list of temporary variables \cr
  272. \f{()} & ;list of value forms \cr
  273. \f{(g0001)} & ;list of store variables \cr
  274. \f{(setq \param{x} g0001)} & ;storing form \cr
  275. \param{x} & ;accessing form \cr
  276. }
  277. %% 7.2.0 70
  278. For {\tt (car \param{exp})}:
  279. \showtwo{Sample Setf Expansion of a CAR Form}{
  280. \f{(g0002)} & ;list of temporary variables \cr
  281. \f{(\param{exp})} & ;list of value forms \cr
  282. \f{(g0003)} & ;list of store variables \cr
  283. \f{(progn (rplaca g0002 g0003) g0003)} & ;storing form \cr
  284. \f{(car g0002)} & ;accessing form \cr
  285. }
  286. %% 7.2.0 71
  287. For \f{(subseq \param{seq} \param{s} \param{e})}:
  288. \showtwo{Sample Setf Expansion of a SUBSEQ Form}{
  289. \f{(g0004 g0005 g0006)} & ;list of temporary variables \cr
  290. \f{(\param{seq} \param{s} \param{e})} & ;list of value forms \cr
  291. \f{(g0007)} & ;list of store variables \cr
  292. \f{(progn (replace g0004 g0007 :start1 g0005 :end1 g0006) g0007)} \span \cr
  293. & ;storing form \cr
  294. \f{(subseq g0004 g0005 g0006)} & ; accessing form \cr
  295. }
  296. In some cases, if a \term{subform} of a \term{place} is itself
  297. a \term{place}, it is necessary to expand the \term{subform}
  298. in order to compute some of the values in the expansion of the outer
  299. \term{place}. For \f{(ldb \param{bs} (car \param{exp}))}:
  300. \showtwo{Sample Setf Expansion of a LDB Form}{
  301. \f{(g0001 g0002)} & ;list of temporary variables \cr
  302. \f{(\param{bs} \param{exp})} & ;list of value forms \cr
  303. \f{(g0003)} & ;list of store variables \cr
  304. \f{(progn (rplaca g0002 (dpb g0003 g0001 (car g0002))) g0003)} \span \cr
  305. & ;storing form \cr
  306. \f{(ldb g0001 (car g0002))} & ; accessing form \cr
  307. }
  308. \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  309. \endsubsubsubsection%{Examples of Setf Expansions}
  310. \endsubsubsection%{Setf Expansions}
  311. \endsubSection%{Overview of Places and Generalized Reference}
  312. \beginsubSection{Kinds of Places}
  313. \DefineSection{KindsOfPlaces}
  314. %% 7.2.0 7
  315. Several kinds of \term{places} are defined by \clisp;
  316. this section enumerates them.
  317. This set can be extended by \term{implementations} and by \term{programmer code}.
  318. %% 7.2.0 8
  319. \beginsubsubsection{Variable Names as Places}
  320. The name of a \term{lexical variable} or \term{dynamic variable}
  321. can be used as a \term{place}.
  322. \endsubsubsection%{Variable Names as Places}
  323. %% 7.2.0 9
  324. \beginsubsubsection{Function Call Forms as Places}
  325. \DefineSection{FnFormsAsGenRefs}
  326. A \term{function form} can be used as a \term{place} if it falls
  327. into one of the following categories:
  328. \beginlist
  329. \itemitem{\bull}
  330. A function call form whose first element is the name of
  331. any one of the functions in \thenextfigure.
  332. %% Barmar: Unnecessary as binding these symbols is disallowed.
  333. % \issue{FUNCTION-NAME:LARGE}
  334. % The function name must refer to the global function definition,
  335. % rather than a locally defined \term{function}.
  336. % \endissue{FUNCTION-NAME:LARGE}
  337. %!!! CLASS-NAME and DOCUMENTATION maybe deserve their own table,
  338. % since they are the only two defined by setf method.
  339. \issue{CONDITION-ACCESSORS-SETFABLE:NO}
  340. \editornote{KMP: Note that what are in some places still called `condition accessors'
  341. are deliberately omitted from this table, and are not labeled as
  342. accessors in their entries. I have not yet had time to do a full
  343. search for these items and eliminate stray references to them as `accessors',
  344. which they are not, but I will do that at some point.}%!!!
  345. \issue{PATHNAME-LOGICAL:ADD}
  346. \issue{AREF-1D}
  347. \issue{FUNCTION-NAME:LARGE}
  348. %Merged BIT, SBIT, CHAR, SCHAR, and SUBSEQ from next table on advice of Moon and others.
  349. % -kmp 13-Feb-92
  350. % I added COMPILER-MACRO-FUNCTION, READTABLE-CASE, and SLOT-VALUE,
  351. % which were also missing. --sjl 5 Mar 92
  352. \displaythree{Functions that setf can be used with---1}{
  353. aref&cdadr&get\cr
  354. bit&cdar&gethash\cr
  355. caaaar&cddaar&logical-pathname-translations\cr
  356. caaadr&cddadr&macro-function\cr
  357. caaar&cddar&ninth\cr
  358. caadar&cdddar&nth\cr
  359. caaddr&cddddr&readtable-case\cr
  360. caadr&cdddr&rest\cr
  361. caar&cddr&row-major-aref\cr
  362. cadaar&cdr&sbit\cr
  363. cadadr&char&schar\cr
  364. cadar&class-name&second\cr
  365. caddar&compiler-macro-function&seventh\cr
  366. cadddr&documentation&sixth\cr
  367. caddr&eighth&slot-value\cr
  368. cadr&elt&subseq\cr
  369. car&fdefinition&svref\cr
  370. cdaaar&fifth&symbol-function\cr
  371. cdaadr&fill-pointer&symbol-plist\cr
  372. cdaar&find-class&symbol-value\cr
  373. cdadar&first&tenth\cr
  374. cdaddr&fourth&third\cr
  375. }
  376. \endissue{FUNCTION-NAME:LARGE}
  377. \endissue{AREF-1D}
  378. \endissue{PATHNAME-LOGICAL:ADD}
  379. \endissue{CONDITION-ACCESSORS-SETFABLE:NO}
  380. %% This text used to belong after the next table, which is now commented out. -kmp 13-Feb-92
  381. In the case of \funref{subseq}, the replacement value must be a \term{sequence}
  382. whose elements might be contained by the sequence argument to \funref{subseq},
  383. but does not have to be a \term{sequence} of the same \term{type}
  384. %!!! Moon thinks this next is awkward.
  385. as the \term{sequence} of which the subsequence is specified.
  386. If the length of the replacement value does not equal the length of
  387. the subsequence to be replaced, then the shorter length determines
  388. the number of elements to be stored, as for \funref{replace}.
  389. \itemitem{\bull}
  390. %% 7.2.0 10
  391. A function call form whose first element is the name of
  392. a selector function constructed by \macref{defstruct}.
  393. %% Barmar: Unnecessary as binding these symbols is disallowed.
  394. %% KMP: I'm not so sure in this case.
  395. \issue{FUNCTION-NAME:LARGE}
  396. The function name must refer to the global function definition,
  397. rather than a locally defined \term{function}.
  398. \endissue{FUNCTION-NAME:LARGE}
  399. %% Moon:
  400. %% The distinction between this and the previous table is strange. After all,
  401. %% fill-pointer, symbol-function, and class-name have type restrictions, too.
  402. %% Also, the text above this table seems garbled. I would merge these into previous
  403. %% and delete the text.
  404. %% KMP: Done. (13-Feb-92)
  405. %
  406. % \itemitem{\bull}
  407. % %% 7.2.0 11
  408. % A function call form whose first element is the name of
  409. % any one of the functions in \thenextfigure,
  410. % provided that the new value
  411. % is of the specified type so that it can be used to
  412. % place in the specified ``location'' (which is in each of these cases
  413. % not truly a \term{place}).
  414. % %% Barmar: Unnecessary as binding these symbols is disallowed.
  415. % % \issue{FUNCTION-NAME:LARGE}
  416. % % The function name must refer to the global
  417. % % function definition, rather than a locally defined \term{function}.
  418. % % \endissue{FUNCTION-NAME:LARGE}
  419. %
  420. % \issue{CHARACTER-PROPOSAL:2-1-1}
  421. % \tablefigtwo{Functions that setf can be used with---n}{Function name}{Required type}{
  422. % \funref{bit}&\typeref{bit}\cr
  423. % \funref{sbit}&\typeref{bit}\cr
  424. % \funref{char}&\typeref{character}\cr
  425. % \funref{schar}&\typeref{character}\cr
  426. % \funref{subseq}&\typeref{sequence}\cr
  427. % }
  428. % \endissue{CHARACTER-PROPOSAL:2-1-1}
  429. \itemitem{\bull}
  430. %% 7.2.0 12
  431. A function call form whose first element is the name of
  432. any one of the functions in \thenextfigure,
  433. provided that the supplied argument
  434. to that function is in turn a \term{place} form;
  435. in this case the new \term{place} has stored back into it the
  436. result of applying the supplied ``update'' function.
  437. %% Moon thought this next was just confusing.
  438. %(which is in each of these cases not a true update function).
  439. %% Barmar: Unnecessary as binding these symbols is disallowed.
  440. % \issue{FUNCTION-NAME:LARGE}
  441. % The function name must refer to the global function
  442. % definition, rather than a locally defined \term{function}.
  443. % \endissue{FUNCTION-NAME:LARGE}
  444. \issue{SETF-SUB-METHODS:DELAYED-ACCESS-STORES}
  445. \tablefigthree{Functions that setf can be used with---2}{Function name}{Argument that is a \param{place}}{Update function used}{
  446. \funref{ldb} & second & \funref{dpb} \cr
  447. \funref{mask-field} & second & \funref{deposit-field} \cr
  448. \funref{getf} & first & \term{implementation-dependent} \cr
  449. }
  450. %% Moon thinks this is redundant.
  451. % The \param{place} forms listed in the above figure admit other
  452. % \param{places} as arguments; these are called sub-recursive \param{places}.
  453. During the \macref{setf} expansion of these \term{forms}, it is necessary to call
  454. \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  455. \funref{get-setf-expansion}
  456. \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  457. in order to figure out how the inner, nested generalized variable must be treated.
  458. The information from
  459. \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  460. \funref{get-setf-expansion}
  461. \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  462. is used as follows.
  463. \beginlist
  464. \issue{CHARACTER-PROPOSAL:2-1-1}
  465. %References to CHAR-BIT omitted.
  466. \endissue{CHARACTER-PROPOSAL:2-1-1}
  467. \itemitem{\funref{ldb}}
  468. In a form such as:
  469. {\tt (setf (ldb \param{byte-spec} \param{place-form}) \param{value-form})}
  470. the place referred to by the \param{place-form} must always be both \term{read}
  471. and \term{written}; note that the update is to the generalized variable
  472. specified by \param{place-form}, not to any object \oftype{integer}.
  473. Thus this \macref{setf} should generate code to do the following:
  474. \beginlist
  475. \itemitem{1.} Evaluate \param{byte-spec} (and bind it into a temporary variable).
  476. \itemitem{2.} Bind the temporary variables for \param{place-form}.
  477. \itemitem{3.} Evaluate \param{value-form} (and bind
  478. \issue{SETF-MULTIPLE-STORE-VARIABLES:ALLOW}
  479. its value or values into the store variable).
  480. %% Moon: Can only be ONE store variable here.
  481. % or variables
  482. \endissue{SETF-MULTIPLE-STORE-VARIABLES:ALLOW}
  483. \itemitem{4.} Do the \term{read} from \param{place-form}.
  484. \itemitem{5.} Do the \term{write} into \param{place-form} with
  485. the given bits of the \term{integer}
  486. fetched in step 4 replaced with the value from step 3.
  487. \endlist
  488. If the evaluation of \param{value-form}
  489. in step 3 alters what is found in \param{place-form},
  490. such as setting different bits of \term{integer},
  491. then the change of the bits denoted by
  492. \param{byte-spec} is to that
  493. altered \term{integer},
  494. because step 4 is done after the \param{value-form}
  495. evaluation. Nevertheless, the
  496. evaluations required for \term{binding}
  497. the temporary variables are done in steps 1 and
  498. 2, and thus the expected left-to-right evaluation order is seen.
  499. For example:
  500. \code
  501. (setq integer #x69) \EV #x69
  502. (rotatef (ldb (byte 4 4) integer)
  503. (ldb (byte 4 0) integer))
  504. integer \EV #x96
  505. ;;; This example is trying to swap two independent bit fields
  506. ;;; in an integer. Note that the generalized variable of
  507. ;;; interest here is just the (possibly local) program variable
  508. ;;; integer.
  509. \endcode
  510. \itemitem{\funref{mask-field}}
  511. This case is the same as \funref{ldb} in all essential aspects.
  512. \itemitem{\funref{getf}}
  513. In a form such as:
  514. \f{(setf (getf \param{place-form} \param{ind-form}) \param{value-form})}
  515. the place referred to by \param{place-form} must always be both \term{read}
  516. and \term{written}; note that the update is to the generalized variable
  517. specified by \param{place-form}, not necessarily to the particular
  518. \term{list}
  519. that is the property list in question.
  520. Thus this \macref{setf} should generate code to do the following:
  521. \beginlist
  522. \itemitem{1.}
  523. Bind the temporary variables for \param{place-form}.
  524. \itemitem{2.}
  525. Evaluate \param{ind-form} (and bind it into a temporary variable).
  526. \itemitem{3.}
  527. Evaluate \param{value-form} (and bind
  528. \issue{SETF-MULTIPLE-STORE-VARIABLES:ALLOW}
  529. its value or values into the store variable).
  530. %%Moon: Can only be one store variable
  531. % or variables
  532. \endissue{SETF-MULTIPLE-STORE-VARIABLES:ALLOW}
  533. \itemitem{4.}
  534. Do the \term{read} from \param{place-form}.
  535. \itemitem{5.}
  536. Do the \term{write} into \param{place-form} with a possibly-new property list
  537. obtained by combining the values from steps 2, 3, and 4.
  538. (Note that the phrase ``possibly-new property list'' can mean that
  539. the former property list is somehow destructively re-used, or it can
  540. mean partial or full copying of it.
  541. Since either copying or destructive re-use can occur,
  542. the treatment of the resultant value for the
  543. possibly-new property list must proceed as if it were a different copy
  544. needing to be stored back into the generalized variable.)
  545. \endlist
  546. If the evaluation of \param{value-form}
  547. in step 3 alters what is found in
  548. \param{place-form}, such as setting a different named property in the list,
  549. then the change of the property denoted by \param{ind-form}
  550. is to that
  551. altered list, because step 4 is done after the
  552. \param{value-form}
  553. evaluation. Nevertheless, the
  554. evaluations required for \term{binding}
  555. the temporary variables are done in steps 1 and
  556. 2, and thus the expected left-to-right evaluation order is seen.
  557. For example:
  558. \code
  559. (setq s (setq r (list (list 'a 1 'b 2 'c 3)))) \EV ((a 1 b 2 c 3))
  560. (setf (getf (car r) 'b)
  561. (progn (setq r nil) 6)) \EV 6
  562. r \EV NIL
  563. s \EV ((A 1 B 6 C 3))
  564. ;;; Note that the (setq r nil) does not affect the actions of
  565. ;;; the SETF because the value of R had already been saved in
  566. ;;; a temporary variable as part of the step 1. Only the CAR
  567. ;;; of this value will be retrieved, and subsequently modified
  568. ;;; after the value computation.
  569. \endcode
  570. \endlist
  571. \endlist
  572. \endissue{SETF-SUB-METHODS:DELAYED-ACCESS-STORES}
  573. \endsubsubsection%{Function Call Forms as Places}
  574. % This section added. --sjl 4 Mar 92
  575. \issue{SETF-OF-VALUES:ADD}
  576. \beginsubsubsection{VALUES Forms as Places}
  577. \DefineSection{SETFofVALUES}
  578. A \funref{values} \term{form} can be used as a \term{place},
  579. provided that each of its \term{subforms} is also a \term{place} form.
  580. A form such as
  581. {\tt (setf (values \param{place-1} \dots \param{place-n}) \param{values-form})}
  582. does the following:
  583. \beginlist
  584. \itemitem{1.} The \term{subforms} of each nested \param{place} are evaluated
  585. in left-to-right order.
  586. \itemitem{2.} The \param{values-form} is evaluated, and the first store
  587. variable from each \param{place} is bound to its return values as if by
  588. \macref{multiple-value-bind}.
  589. \itemitem{3.} If the \term{setf expansion} for any \param{place}
  590. involves more than one store variable, then the additional
  591. store variables are bound to \nil.
  592. \itemitem{4.} The storing forms for each \param{place} are evaluated in
  593. left-to-right order.
  594. \endlist
  595. The storing form in the \term{setf expansion} of \funref{values}
  596. returns as \term{multiple values}\meaning{2} the values of the store
  597. variables in step 2. That is, the number of values returned is the
  598. same as the number of \term{place} forms. This may be more or fewer
  599. values than are produced by the \param{values-form}.
  600. % There probably ought to be some examples here.
  601. \endsubsubsection%{VALUES Forms as Places}
  602. \endissue{SETF-OF-VALUES:ADD}
  603. \beginsubsubsection{THE Forms as Places}
  604. %% 7.2.0 13
  605. A \specref{the} \term{form} can be used as a \term{place},
  606. in which case the declaration is transferred to the \param{newvalue} form,
  607. and the resulting \macref{setf} is analyzed. For example,
  608. \code
  609. (setf (the integer (cadr x)) (+ y 3))
  610. \endcode
  611. is processed as if it were
  612. \code
  613. (setf (cadr x) (the integer (+ y 3)))
  614. \endcode
  615. \endsubsubsection%{THE Forms as Places}
  616. \issue{SETF-APPLY-EXPANSION:IGNORE-EXPANDER}
  617. \issue{SETF-OF-APPLY:ONLY-AREF-AND-FRIENDS}
  618. \issue{JUN90-TRIVIAL-ISSUES:27}
  619. \beginsubsubsection{APPLY Forms as Places}
  620. \DefineSection{SETFofAPPLY}
  621. The following situations involving \macref{setf} of \funref{apply} must be supported:
  622. \beginlist
  623. \itemitem{\bull} \f{(setf (apply \#'aref \param{array}
  624. \starparam{subscript}
  625. \param{more-subscripts})
  626. \param{new-element})}
  627. \itemitem{\bull} \f{(setf (apply \#'bit \param{array}
  628. \starparam{subscript}
  629. \param{more-subscripts})
  630. \param{new-element})}
  631. \itemitem{\bull} \f{(setf (apply \#'sbit \param{array}
  632. \starparam{subscript}
  633. \param{more-subscripts})
  634. \param{new-element})}
  635. \endlist
  636. In all three cases, the \term{element} of \param{array} designated
  637. by the concatenation of \param{subscripts} and \param{more-subscripts}
  638. (\ie the same \term{element} which would be \term{read} by the call to
  639. \term{apply} if it were not part of a \macref{setf} \term{form})
  640. is changed to have the \term{value} given by \param{new-element}.
  641. \issue{FUNCTION-NAME:LARGE}
  642. For these usages, the function name (\funref{aref}, \funref{bit}, or \funref{sbit})
  643. must refer to the global function definition, rather than a locally defined
  644. \term{function}.
  645. \endissue{FUNCTION-NAME:LARGE}
  646. No other \term{standardized} \term{function} is required to be supported,
  647. but an \term{implementation} may define such support.
  648. An \term{implementation} may also define support
  649. for \term{implementation-defined} \term{operators}.
  650. If a user-defined \term{function} is used in this context,
  651. the following equivalence is true, except that care is taken
  652. to preserve proper left-to-right evaluation of argument \term{subforms}:
  653. \code
  654. (setf (apply \#'\param{name} \starparam{arg}) \param{val})
  655. \EQ (apply \#'(setf \param{name}) \param{val} \starparam{arg})
  656. \endcode
  657. % Removed reference to (setf (apply #'name a1 a2 ...) (values v1 v2 ...)) as bogus.
  658. \endsubsubsection%{APPLY Forms as Places}
  659. \endissue{JUN90-TRIVIAL-ISSUES:27}
  660. \endissue{SETF-OF-APPLY:ONLY-AREF-AND-FRIENDS}
  661. \endissue{SETF-APPLY-EXPANSION:IGNORE-EXPANDER}
  662. \beginsubsubsection{Setf Expansions and Places}
  663. % \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  664. % \itemitem{\macref{defsetf} or \macref{define-setf-expander} declarations}
  665. % \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  666. %% 7.2.0 17
  667. Any \term{compound form} for which the \term{operator} has a
  668. \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  669. \term{setf expander}
  670. \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  671. defined can be used as a \term{place}.
  672. \issue{FUNCTION-NAME:LARGE}
  673. The
  674. % function name that is the \param{access-fn}
  675. % argument to \macref{defsetf} or
  676. % \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  677. % \macref{define-setf-expander}
  678. % \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  679. %% previous phrase replaced by Moon as just "operator" -kmp 4-Dec-91
  680. \term{operator}
  681. must refer to the global function definition,
  682. rather than a locally defined \term{function} or \term{macro}.
  683. \endissue{FUNCTION-NAME:LARGE}
  684. \issue{FUNCTION-NAME:LARGE}
  685. \endsubsubsection%{Setf Expansions and Places}
  686. %% 7.2.0 16
  687. \beginsubsubsection{Macro Forms as Places}
  688. A \term{macro form} can be used as a \term{place},
  689. in which case \clisp\ expands the \term{macro form}
  690. \issue{FUNCTION-NAME:LARGE}
  691. as if by \funref{macroexpand-1}
  692. \endissue{FUNCTION-NAME:LARGE}
  693. and then uses the \term{macro expansion} in place of the original \term{place}.
  694. \issue{SETF-MACRO-EXPANSION:LAST}
  695. %This is true for GET-SETF-EXPANSION, too, but there's no obvious place to say that.
  696. % -kmp 5-Jun-91
  697. Such \term{macro expansion} is attempted only after exhausting all other possibilities
  698. other than expanding into a call to a function named \f{(setf \param{reader})}.
  699. \endissue{SETF-MACRO-EXPANSION:LAST}
  700. \endsubsubsection%{Macro Forms as Places}
  701. % I moved this section here from below. --sjl 5 Mar 92
  702. \issue{SYMBOL-MACROLET-SEMANTICS:SPECIAL-FORM}
  703. \beginsubsubsection{Symbol Macros as Places}
  704. A reference to a \term{symbol} that has been \term{established} as a \term{symbol macro}
  705. can be used as a \term{place}. In this case,
  706. \macref{setf} expands the reference and then analyzes the resulting \term{form}.
  707. \endissue{SYMBOL-MACROLET-SEMANTICS:SPECIAL-FORM}
  708. \endsubsubsection%{Symbol Macros as Places}
  709. \beginsubsubsection{Other Compound Forms as Places}
  710. For any other \term{compound form} for which the \term{operator} is a
  711. \term{symbol} \param{f},
  712. the \macref{setf} \term{form} expands into a call
  713. to the \term{function} named \f{(setf \param{f})}.
  714. The first \term{argument} in the newly constructed \term{function form}
  715. is \param{newvalue} and the
  716. remaining \term{arguments} are the remaining \term{elements} of
  717. \param{place}.
  718. This expansion occurs regardless of whether \param{f} or \f{(setf \param{f})}
  719. is defined as a \term{function} locally, globally, or not at all.
  720. For example,
  721. \f{(setf (\param{f} \param{arg1} \param{arg2} ...) \param{new-value})}
  722. expands into a form with the same effect and value as
  723. \code
  724. (let ((#:temp-1 arg1) ;force correct order of evaluation
  725. (#:temp-2 arg2)
  726. ...
  727. (#:temp-0 \param{new-value}))
  728. (funcall (function (setf \param{f})) #:temp-0 #:temp-1 #:temp-2...))
  729. \endcode
  730. A \term{function} named \f{(setf \param{f})} must return its first argument
  731. as its only value in order to preserve the semantics of \macref{setf}.
  732. \endissue{FUNCTION-NAME:LARGE}
  733. \endsubsubsection%{Other Compound Forms as Places}
  734. % I moved the symbol macro section up to be with the ordinary macro
  735. % section. --sjl 5 Mar 92
  736. \endsubSection%{Kinds of Places}
  737. \beginsubSection{Treatment of Other Macros Based on SETF}
  738. \issue{READ-MODIFY-WRITE-EVALUATION-ORDER:DELAYED-ACCESS-STORES}
  739. For each of the ``read-modify-write'' \term{operators} in \thenextfigure,
  740. and for any additional \term{macros}
  741. defined by the \term{programmer} using \macref{define-modify-macro},
  742. an exception is made to the normal rule of left-to-right evaluation of arguments.
  743. Evaluation of \term{argument} \term{forms} occurs in left-to-right order,
  744. with the exception that for the \param{place} \term{argument}, the actual
  745. \term{read} of the ``old value'' from that \param{place} happens
  746. after all of the \term{argument} \term{form} \term{evaluations},
  747. and just before a ``new value'' is computed and \term{written} back into the \param{place}.
  748. Specifically, each of these \term{operators} can be viewed as involving a
  749. \term{form} with the following general syntax:
  750. \code
  751. (\term{operator} \starparam{preceding-form} \param{place} \starparam{following-form})
  752. \endcode
  753. The evaluation of each such \term{form} proceeds like this:
  754. \beginlist
  755. \itemitem{1.} \term{Evaluate} each of the \param{preceding-forms}, in left-to-right order.
  756. \itemitem{2.} \term{Evaluate} the \term{subforms} of the \param{place},
  757. in the order specified by the second value of the \term{setf expansion}
  758. for that \param{place}.
  759. \itemitem{3.} \term{Evaluate} each of the \param{following-forms}, in left-to-right order.
  760. \itemitem{4.} \term{Read} the old value from \param{place}.
  761. \itemitem{5.} Compute the new value.
  762. \itemitem{6.} Store the new value into \param{place}.
  763. \endlist
  764. \displaythree{Read-Modify-Write Macros}{
  765. decf&pop&pushnew\cr
  766. incf&push&remf\cr
  767. }
  768. \endissue{READ-MODIFY-WRITE-EVALUATION-ORDER:DELAYED-ACCESS-STORES}
  769. \endsubSection%{Treatment of Other Macros Based on SETF}