concept-bvl.tex 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286
  1. % -*- Mode: TeX -*-
  2. A \newterm{lambda list} is a \term{list} that
  3. specifies a set of \term{parameters} (sometimes called \term{lambda variables})
  4. and a protocol for receiving \term{values} for those \term{parameters}.
  5. % \term{Lambda list keywords} do not belong to \thepackage{keyword};
  6. % a \term{lambda list keyword} is a \term{symbol}
  7. % whose name begins with an \term{ampersand}.
  8. There are several kinds of \term{lambda lists}.
  9. \tablefigtwo{What Kind of Lambda Lists to Use}{Context}{Kind of Lambda List}{
  10. \macref{defun} \term{form} & \term{ordinary lambda list} \cr
  11. \macref{defmacro} \term{form} & \term{macro lambda list} \cr
  12. \term{lambda expression} & \term{ordinary lambda list} \cr
  13. \specref{flet} local \term{function} definition & \term{ordinary lambda list} \cr
  14. \specref{labels} local \term{function} definition & \term{ordinary lambda list} \cr
  15. \specref{handler-case} \param{clause} specification
  16. & \term{ordinary lambda list} \cr
  17. \specref{restart-case} \param{clause} specification
  18. & \term{ordinary lambda list} \cr
  19. \macref{macrolet} local \term{macro} definition & \term{macro lambda list} \cr
  20. \macref{define-method-combination} & \term{ordinary lambda list} \cr
  21. \macref{define-method-combination} \kwd{arguments} option &
  22. %Moon thought :arguments for DEFINE-METHOD-COMBINATION took an ordinary lambda list,
  23. %but Barrett (comment #3, first public review) observes that &whole is permissible.
  24. %Time to make a new kind of list.
  25. \term{define-method-combination arguments lambda list} \cr
  26. \macref{defstruct} \kwd{constructor} option & \term{boa lambda list} \cr
  27. \macref{defgeneric} \term{form} & \term{generic function lambda list} \cr
  28. \macref{defgeneric} \term{method} clause & \term{specialized lambda list} \cr
  29. \macref{defmethod} \term{form} & \term{specialized lambda list} \cr
  30. \macref{defsetf} \term{form} & \term{defsetf lambda list} \cr
  31. \macref{define-setf-expander} \term{form} & \term{macro lambda list} \cr
  32. \macref{deftype} \term{form} & \term{deftype lambda list} \cr
  33. \macref{destructuring-bind} \term{form} & \term{destructuring lambda list} \cr
  34. %\specref{generic-flet} \term{form} & \term{generic function lambda list} \cr
  35. %\specref{generic-flet} \term{method} clause & \term{specialized lambda list} \cr
  36. %\specref{generic-labels} \term{form} & \term{generic function lambda list} \cr
  37. %\specref{generic-labels} \term{method} clause & \term{specialized lambda list} \cr
  38. %\specref{generic-function} \term{form} & \term{generic function lambda list} \cr
  39. %\specref{generic-function} \term{method} clause & \term{specialized lambda list} \cr
  40. % Added define-modify-macro and define-compiler-macro --sjl 5 Mar 92
  41. \macref{define-compiler-macro} \term{form} & \term{macro lambda list} \cr
  42. \macref{define-modify-macro} \term{form} & \term{define-modify-macro lambda list} \cr
  43. }
  44. \Thenextfigure\ lists some \term{defined names} that are applicable
  45. to \term{lambda lists}.
  46. \displaythree{Defined names applicable to lambda lists}{
  47. lambda-list-keywords&lambda-parameters-limit&\cr
  48. }
  49. \beginsubSection{Ordinary Lambda Lists}
  50. \DefineSection{OrdinaryLambdaLists}
  51. An \newterm{ordinary lambda list} is used to describe how a set of
  52. \term{arguments} is received by an \term{ordinary} \term{function}.
  53. The \term{defined names} in \thenextfigure\ are those which use
  54. \term{ordinary lambda lists}:
  55. %!!! This table is just a seed and probably incomplete. -kmp 2-Aug-91
  56. %Added RESTART-CASE and HANDLER-CASE per Moon #9 (first public review). -kmp 6-May-93
  57. \displaythree{Standardized Operators that use Ordinary Lambda Lists}{
  58. define-method-combination&handler-case&restart-case\cr
  59. defun&labels&\cr
  60. flet&lambda&\cr
  61. }
  62. An \term{ordinary lambda list} can contain the \term{lambda list keywords} shown
  63. in \thenextfigure.
  64. \showthree{Lambda List Keywords used by Ordinary Lambda Lists}{
  65. \keyref{allow-other-keys}&\keyref{key}&\keyref{rest}\cr
  66. \keyref{aux}&\keyref{optional}&\cr
  67. }
  68. Each \term{element} of a \term{lambda list} is either a parameter specifier
  69. or a \term{lambda list keyword}.
  70. %%5.2.2 26
  71. Implementations are free to provide additional \term{lambda list keywords}.
  72. For a list of all \term{lambda list keywords}
  73. used by the implementation, see \conref{lambda-list-keywords}.
  74. The syntax for \term{ordinary lambda lists} is as follows:
  75. \Vskip 1pc!
  76. \auxbnf{lambda-list}{\lparen\starparam{var}\CR
  77. \ \ttbrac{{\opt} \star{\VarValueSuppliedP}}\CR
  78. \ \ttbrac{{\rest} \param{var}}\CR
  79. \ \f{[}\Vtop{\hbox{{\key} \star{\KeyVarValueSuppliedP}}
  80. \vskip 4pt
  81. \hbox{\brac{\allowotherkeys}\f{]}}}\CR
  82. \ \ttbrac{{\aux} \star{\VarValue}}\rparen\CR}
  83. %% 5.2.2 3
  84. A \param{var} or \param{supplied-p-parameter} must be a \term{symbol}
  85. that is not the name of a \term{constant variable}.
  86. An \param{init-form} can be any \term{form}.
  87. %% 5.2.2 22
  88. Whenever any \param{init-form} is evaluated for any parameter
  89. specifier, that \term{form} may refer to any parameter variable to
  90. the left of the specifier in which the \param{init-form} appears,
  91. including any \param{supplied-p-parameter} variables, and may rely
  92. on the fact that no other parameter variable has yet been bound
  93. (including its own parameter variable).
  94. A \param{keyword-name} can be any \term{symbol},
  95. but by convention is normally a \term{keyword}\meaning{1};
  96. all \term{standardized} \term{functions} follow that convention.
  97. %% 5.2.2 4
  98. An \term{ordinary lambda list} has five parts, any or all of which may be empty.
  99. For information about the treatment of argument mismatches,
  100. \seesection\FuncallErrorChecking.
  101. %% 5.2.2 9
  102. %% 5.2.2 11
  103. \beginsubsubsection{Specifiers for the required parameters}
  104. These are all the parameter specifiers up to
  105. the first \term{lambda list keyword};
  106. if there are no \term{lambda list keywords},
  107. then all the specifiers are for required parameters.
  108. Each required parameter is specified by a parameter variable \param{var}.
  109. \param{var} is bound as a lexical variable unless it is declared \declref{special}.
  110. %!!! Moon: There has been a cleanup that says when an error is signaled.
  111. If there are \f{n} required parameters (\f{n} may be zero),
  112. there must be at least \f{n} passed arguments, and the
  113. required parameters are bound to the first \f{n} passed arguments;
  114. \seesection\FuncallErrorChecking.
  115. The other parameters are then processed using any remaining arguments.
  116. \endsubsubsection%{Specifiers for the required parameters}
  117. %% 5.2.2 12
  118. \beginsubsubsection{Specifiers for optional parameters}
  119. \idxkeyref{optional}
  120. If \keyref{optional} is present,
  121. the optional parameter specifiers are those following
  122. \keyref{optional}
  123. up to the next \term{lambda list keyword} or the end of the list.
  124. If optional parameters are specified, then each one is processed as
  125. follows. If any unprocessed arguments remain, then the parameter variable
  126. \param{var} is bound to the next remaining argument, just as for a required
  127. parameter. If no arguments remain, however, then \param{init-form}
  128. is evaluated, and the parameter variable
  129. is bound to the resulting value
  130. (or to \nil\ if no \param{init-form} appears
  131. in the parameter specifier).
  132. If another variable name \param{supplied-p-parameter}
  133. appears in the specifier, it is bound
  134. to \term{true} if an argument had been available, and to \term{false} if no
  135. argument remained (and therefore \param{init-form} had to be evaluated).
  136. \param{Supplied-p-parameter}
  137. is bound not to an argument but to a value indicating whether or not
  138. an argument had been supplied for the corresponding \param{var}.
  139. \endsubsubsection%{Specifiers for optional parameters}
  140. %% 5.2.2 13
  141. \beginsubsubsection{A specifier for a rest parameter}
  142. \idxkeyref{rest}
  143. \keyref{rest}, if present, must be followed by a single \term{rest parameter}
  144. specifier, which in turn must be followed by another
  145. \term{lambda list keyword} or the end of the \term{lambda list}. After all
  146. optional parameter specifiers have been processed, then there may or
  147. may not be a \term{rest parameter}. If there is a \term{rest parameter}, it is
  148. bound to a \term{list} of all as-yet-unprocessed arguments. If
  149. no unprocessed arguments remain, the \term{rest parameter} is bound to the
  150. \term{empty list}. If there is no \term{rest parameter} and there are no
  151. \term{keyword parameters}, then an error
  152. %% Per Barrett #10 -- the actual type is more specific, and specified elsewhere. -kmp 7-May-93
  153. %\oftype{error}
  154. should be signaled if
  155. any unprocessed arguments remain; \seesection\FuncallErrorChecking.
  156. The value of a \term{rest parameter}
  157. is permitted, but not required, to share structure with the
  158. last argument to \funref{apply}.
  159. \endsubsubsection%{A specifier for a rest parameter}
  160. \idxkeyref{key}
  161. \idxkeyref{allow-other-keys}
  162. %% 5.2.2 14
  163. \beginsubsubsection{Specifiers for keyword parameters}
  164. \issue{PLIST-DUPLICATES:ALLOW}
  165. %!!! I didn't integrate item 5 of PLIST-DUPLICATES because it seemed dangerous
  166. % to change this section for very little apparent gain. There was no technical
  167. % change implied by that item. -kmp 14-Jul-93
  168. If \keyref{key}
  169. is present, all specifiers up to the next \term{lambda list keyword}
  170. or the end of the \term{list} are keyword parameter specifiers.
  171. When keyword parameters are processed,
  172. the same arguments are processed that
  173. would be made into a \term{list} for a \term{rest parameter}.
  174. It is permitted to specify both \keyref{rest} and \keyref{key}.
  175. In this case the remaining arguments are used for both purposes;
  176. that is, all remaining arguments are made into a \term{list} for the
  177. \term{rest parameter}, and are also processed for the \keyref{key} parameters.
  178. \issue{ARGUMENT-MISMATCH-ERROR-AGAIN:CONSISTENT}
  179. If \keyref{key} is specified, there must remain
  180. an even number of arguments; \seesection\OddNumberOfKeyArgs.
  181. \endissue{ARGUMENT-MISMATCH-ERROR-AGAIN:CONSISTENT}
  182. These arguments are considered as pairs,
  183. the first argument in each pair being interpreted as a name
  184. and the second as the corresponding value.
  185. The first \term{object} of each pair must be a \term{symbol};
  186. \seesection\InvalidKeyArgs.
  187. The keyword parameter specifiers may optionally be followed by the
  188. \term{lambda list keyword} \keyref{allow-other-keys}.
  189. %% 5.2.2 16
  190. In each keyword parameter specifier must be a name \param{var} for
  191. the parameter variable.
  192. \issue{KEYWORD-ARGUMENT-NAME-PACKAGE:ANY}
  193. If the \param{var} appears alone or in a \f{(\param{var} \param{init-form})}
  194. combination, the keyword name used when matching \term{arguments} to \term{parameters}
  195. is a \term{symbol} in \thepackage{keyword} whose \term{name} is the
  196. \term{same} (under \funref{string=}) as \param{var}'s.
  197. If the notation \f{((\param{keyword-name} \param{var}) \param{init-form})} is used,
  198. then the keyword name used to match \term{arguments} to \term{parameters} is
  199. \param{keyword-name}, which may be a \term{symbol} in any \term{package}.
  200. (Of course, if it is not a \term{symbol} in \thepackage{keyword},
  201. it does not necessarily self-evaluate, so care must be taken when calling the function
  202. to make sure that normal evaluation still yields the keyword name.)
  203. \endissue{KEYWORD-ARGUMENT-NAME-PACKAGE:ANY}
  204. Thus
  205. \code
  206. (defun foo (&key radix (type 'integer)) ...)
  207. \endcode
  208. means exactly the same as
  209. \code
  210. (defun foo (&key ((:radix radix)) ((:type type) 'integer)) ...)
  211. \endcode
  212. The keyword parameter specifiers are, like all parameter specifiers,
  213. effectively processed from left to right. For each keyword parameter
  214. specifier, if there is an argument pair whose name matches that
  215. specifier's name (that is, the names are \funref{eq}), then the
  216. parameter variable for that specifier is bound to the second item (the
  217. value) of that argument pair. If more than one such argument pair
  218. matches, the leftmost argument pair is used. If no such argument pair
  219. exists, then the \param{init-form} for that specifier is evaluated and
  220. the parameter variable is bound to that value (or to \nil\ if no
  221. \param{init-form} was specified). \param{supplied-p-parameter} is
  222. treated as for \keyref{optional} parameters: it is bound to \term{true} if there
  223. was a matching argument pair, and to \term{false} otherwise.
  224. %% 5.2.2 17
  225. Unless keyword argument checking is suppressed,
  226. an argument pair must a name matched by a parameter specifier;
  227. \seesection\UnrecognizedKeyArgs.
  228. %% 5.2.2 20
  229. % This makes no sense any more because the text referred to has been
  230. % rephrased and moved into its own section below. -- sjl 3 Mar 92
  231. % If either condition obtains,
  232. If keyword argument checking is suppressed,
  233. then it is permitted for an argument pair
  234. to match no parameter specifier, and the argument pair is ignored, but
  235. such an argument pair is accessible through the \term{rest parameter} if
  236. one was supplied. The purpose of these mechanisms is to allow sharing
  237. of argument lists among several \term{lambda expressions} and to
  238. allow either the caller or the called \term{lambda expression} to
  239. specify that such sharing may be taking place.
  240. \issue{ALLOW-OTHER-KEYS-NIL:PERMIT}
  241. Note that if \keyref{key} is present, a keyword argument of \kwd{allow-other-keys}
  242. is always permitted---regardless of whether the associated value is \term{true}
  243. or \term{false}. However, if the value is \term{false}, other non-matching
  244. keywords are not tolerated (unless \keyref{allow-other-keys} was used).
  245. Furthermore, if the receiving argument list specifies a regular argument which
  246. would be flagged by \kwd{allow-other-keys}, then \kwd{allow-other-keys} has both
  247. its special-cased meaning (identifying whether additional keywords are permitted)
  248. and its normal meaning (data flow into the function in question).
  249. \endissue{ALLOW-OTHER-KEYS-NIL:PERMIT}
  250. \endissue{PLIST-DUPLICATES:ALLOW}
  251. \beginsubsubsubsection{Suppressing Keyword Argument Checking}
  252. \DefineSection{SuppressingKeyArgChecks}
  253. If \keyref{allow-other-keys} was specified in the \term{lambda list} of a \term{function},
  254. \term{keyword}\meaning{2} \term{argument} checking is suppressed in calls
  255. to that \term{function}.
  256. If \thekeyarg{allow-other-keys} is \term{true} in a call to a \term{function},
  257. \term{keyword}\meaning{2} \term{argument} checking is suppressed
  258. %% Clarified per Moon #10 (first public review). -kmp 6-May-93
  259. %in calls to that \term{function}.
  260. in that call.
  261. \Thekeyarg{allow-other-keys} is permissible in all situations involving
  262. \term{keyword}\meaning{2} \term{arguments}, even when its associated \term{value}
  263. is \term{false}.
  264. \beginsubsubsubsubsection{Examples of Suppressing Keyword Argument Checking}
  265. \code
  266. ;;; The caller can supply :ALLOW-OTHER-KEYS T to suppress checking.
  267. ((lambda (&key x) x) :x 1 :y 2 :allow-other-keys t) \EV 1
  268. ;;; The callee can use &ALLOW-OTHER-KEYS to suppress checking.
  269. ((lambda (&key x &allow-other-keys) x) :x 1 :y 2) \EV 1
  270. ;;; :ALLOW-OTHER-KEYS NIL is always permitted.
  271. ((lambda (&key) t) :allow-other-keys nil) \EV T
  272. ;;; As with other keyword arguments, only the left-most pair
  273. ;;; named :ALLOW-OTHER-KEYS has any effect.
  274. ((lambda (&key x) x)
  275. :x 1 :y 2 :allow-other-keys t :allow-other-keys nil)
  276. \EV 1
  277. ;;; Only the left-most pair named :ALLOW-OTHER-KEYS has any effect,
  278. ;;; so in safe code this signals a PROGRAM-ERROR (and might enter the
  279. ;;; debugger). In unsafe code, the consequences are undefined.
  280. ((lambda (&key x) x) ;This call is not valid
  281. :x 1 :y 2 :allow-other-keys nil :allow-other-keys t)
  282. \endcode
  283. \endsubsubsubsubsection%{Examples of Suppressing Keyword Argument Checking}
  284. \endsubsubsubsection%{Suppressing Keyword Argument Checking}
  285. \endsubsubsection%{Specifiers for keyword parameters}
  286. %% 5.2.2 21
  287. \beginsubsubsection{Specifiers for \keyref{aux} variables}
  288. \idxkeyref{aux}
  289. These are not really parameters. If the \term{lambda list keyword}
  290. \keyref{aux} is present, all specifiers after it are auxiliary variable
  291. specifiers. After all parameter specifiers have been processed, the
  292. auxiliary variable specifiers (those following {\aux}) are processed
  293. from left to right. For each one, \param{init-form} is evaluated and
  294. \param{var} is bound to that value (or to \nil\ if no \param{init-form}
  295. was specified). \keyref{aux} variable processing is analogous to
  296. \specref{let*} processing.
  297. \code
  298. (lambda (x y &aux (a (car x)) (b 2) c) (list x y a b c))
  299. \EQ (lambda (x y) (let* ((a (car x)) (b 2) c) (list x y a b c)))
  300. \endcode
  301. \endsubsubsection%{Specifiers for \keyref{aux} variables}
  302. \beginsubsubsection{Examples of Ordinary Lambda Lists}
  303. Here are some examples involving \term{optional parameters} and \term{rest parameters}:
  304. \code
  305. ((lambda (a b) (+ a (* b 3))) 4 5) \EV 19
  306. ((lambda (a &optional (b 2)) (+ a (* b 3))) 4 5) \EV 19
  307. ((lambda (a &optional (b 2)) (+ a (* b 3))) 4) \EV 10
  308. ((lambda (&optional (a 2 b) (c 3 d) &rest x) (list a b c d x)))
  309. \EV (2 NIL 3 NIL NIL)
  310. ((lambda (&optional (a 2 b) (c 3 d) &rest x) (list a b c d x)) 6)
  311. \EV (6 T 3 NIL NIL)
  312. ((lambda (&optional (a 2 b) (c 3 d) &rest x) (list a b c d x)) 6 3)
  313. \EV (6 T 3 T NIL)
  314. ((lambda (&optional (a 2 b) (c 3 d) &rest x) (list a b c d x)) 6 3 8)
  315. \EV (6 T 3 T (8))
  316. ((lambda (&optional (a 2 b) (c 3 d) &rest x) (list a b c d x))
  317. 6 3 8 9 10 11)
  318. \EV (6 t 3 t (8 9 10 11))
  319. \endcode
  320. Here are some examples involving \term{keyword parameters}:
  321. \code
  322. ((lambda (a b &key c d) (list a b c d)) 1 2) \EV (1 2 NIL NIL)
  323. ((lambda (a b &key c d) (list a b c d)) 1 2 :c 6) \EV (1 2 6 NIL)
  324. ((lambda (a b &key c d) (list a b c d)) 1 2 :d 8) \EV (1 2 NIL 8)
  325. ((lambda (a b &key c d) (list a b c d)) 1 2 :c 6 :d 8) \EV (1 2 6 8)
  326. ((lambda (a b &key c d) (list a b c d)) 1 2 :d 8 :c 6) \EV (1 2 6 8)
  327. ((lambda (a b &key c d) (list a b c d)) :a 1 :d 8 :c 6) \EV (:a 1 6 8)
  328. ((lambda (a b &key c d) (list a b c d)) :a :b :c :d) \EV (:a :b :d NIL)
  329. ((lambda (a b &key ((:sea c)) d) (list a b c d)) 1 2 :sea 6) \EV (1 2 6 NIL)
  330. ((lambda (a b &key ((c c)) d) (list a b c d)) 1 2 'c 6) \EV (1 2 6 NIL)
  331. \endcode
  332. Here are some examples involving \term{optional parameters}, \term{rest parameters},
  333. and \term{keyword parameters} together:
  334. \code
  335. ((lambda (a &optional (b 3) &rest x &key c (d a))
  336. (list a b c d x)) 1)
  337. \EV (1 3 NIL 1 ())
  338. ((lambda (a &optional (b 3) &rest x &key c (d a))
  339. (list a b c d x)) 1 2)
  340. \EV (1 2 NIL 1 ())
  341. ((lambda (a &optional (b 3) &rest x &key c (d a))
  342. (list a b c d x)) :c 7)
  343. \EV (:c 7 NIL :c ())
  344. ((lambda (a &optional (b 3) &rest x &key c (d a))
  345. (list a b c d x)) 1 6 :c 7)
  346. \EV (1 6 7 1 (:c 7))
  347. ((lambda (a &optional (b 3) &rest x &key c (d a))
  348. (list a b c d x)) 1 6 :d 8)
  349. \EV (1 6 NIL 8 (:d 8))
  350. ((lambda (a &optional (b 3) &rest x &key c (d a))
  351. (list a b c d x)) 1 6 :d 8 :c 9 :d 10)
  352. \EV (1 6 9 8 (:d 8 :c 9 :d 10))
  353. \endcode
  354. %% 5.2.2 28
  355. As an example of the use of \keyref{allow-other-keys} and
  356. \kwd{allow-other-keys}, consider a \term{function} that takes two named
  357. arguments of its own and also accepts additional named arguments to be
  358. passed to \funref{make-array}:
  359. \code
  360. (defun array-of-strings (str dims &rest named-pairs
  361. &key (start 0) end &allow-other-keys)
  362. (apply #'make-array dims
  363. :initial-element (subseq str start end)
  364. :allow-other-keys t
  365. named-pairs))
  366. \endcode
  367. This \term{function} takes a \term{string} and dimensioning
  368. information and returns an \term{array} of the specified
  369. dimensions, each of whose elements is the specified
  370. \term{string}. However, \kwd{start} and \kwd{end} named
  371. arguments may be used to specify that a substring of the given
  372. \term{string} should be used. In addition, the presence of
  373. \keyref{allow-other-keys} in the \term{lambda list} indicates that the
  374. caller may supply additional named arguments; the \term{rest parameter}
  375. provides access to them. These additional named arguments are passed
  376. to \funref{make-array}. The \term{function} \funref{make-array}
  377. normally does not allow the named arguments \kwd{start}
  378. and \kwd{end} to be used, and an error should be
  379. signaled if such named arguments are supplied to \funref{make-array}.
  380. However, the presence in the call to \funref{make-array}
  381. of the named argument \kwd{allow-other-keys} with
  382. a \term{true} value causes any extraneous named arguments, including
  383. \kwd{start} and \kwd{end}, to be acceptable and ignored.
  384. \endsubsubsection%{Examples of Ordinary Lambda Lists}
  385. \endsubSection%{Ordinary Lambda Lists}
  386. \beginsubSection{Generic Function Lambda Lists}
  387. \DefineSection{GFLambdaLists}
  388. A \newterm{generic function lambda list} is used to describe the overall shape of
  389. the argument list to be accepted by a \term{generic function}.
  390. Individual \term{method} \term{signatures} might contribute additional
  391. \term{keyword parameters} to the \term{lambda list} of the \term{effective method}.
  392. %% Might as well not use a table while there's only one. -kmp 15-Feb-92
  393. A \term{generic function lambda list} is used by \macref{defgeneric}.
  394. % \Thenextfigure\ lists the \term{operators} that use \term{generic function lambda lists}.
  395. %
  396. % %!!! This table is just a seed and might be incomplete. -kmp 2-Aug-91
  397. % \issue{GENERIC-FLET-POORLY-DESIGNED:DELETE}
  398. % \displaythree{Standardized Operators that use Generic Function Lambda Lists}{
  399. % defgeneric&&\cr
  400. % % defgeneric&generic-function&\cr
  401. % % generic-flet&generic-labels&\cr
  402. % }
  403. % \endissue{GENERIC-FLET-POORLY-DESIGNED:DELETE}
  404. A \term{generic function lambda list} has the following syntax:
  405. \Vskip 1pc!
  406. \auxbnf{lambda-list}{\lparen\starparam{var}\CR
  407. \ \ttbrac{{\opt} \star{\JustVar}}\CR
  408. \ \ttbrac{{\rest} \param{var}}\CR
  409. \ \f{[}\Vtop{\hbox{{\key} \star{\JustKey}}
  410. \vskip 4pt
  411. \hbox{\brac{\allowotherkeys}\f{]}\rparen}}\CR}
  412. A \term{generic function lambda list} can contain the \term{lambda list keywords} shown
  413. in \thenextfigure.
  414. \showthree{Lambda List Keywords used by Generic Function Lambda Lists}{
  415. \keyref{allow-other-keys}&\keyref{optional}&\cr
  416. \keyref{key}&\keyref{rest}&\cr
  417. }
  418. A \term{generic function lambda list} differs from an \term{ordinary lambda list}
  419. in the following ways:
  420. \beginlist
  421. \itemitem{\bf Required arguments}
  422. % %Per Barmar. -kmp 28-Dec-90
  423. % %At least one
  424. %% Per Moon. -kmp 16-Feb-92
  425. Zero or more \term{required parameters} must be specified.
  426. \itemitem{\bf Optional and keyword arguments}
  427. \term{Optional parameters} and \term{keyword parameters} may not have
  428. default initial value forms nor use supplied-p parameters.
  429. \itemitem{\bf Use of \keyref{aux}}
  430. The use of \keyref{aux} is not allowed.
  431. \endlist
  432. \endsubSection%{Generic Function Lambda Lists}
  433. \goodbreak
  434. \beginsubSection{Specialized Lambda Lists}
  435. \DefineSection{SpecializedLambdaLists}
  436. A \newterm{specialized lambda list} is used to \term{specialize} a \term{method}
  437. for a particular \term{signature} and to describe how \term{arguments} matching
  438. that \term{signature} are received by the \term{method}.
  439. The \term{defined names} in \thenextfigure\ use \term{specialized lambda lists}
  440. in some way; see the dictionary entry for each for information about how.
  441. %!!! This table is just a seed and probably incomplete. -kmp 2-Aug-91
  442. \issue{GENERIC-FLET-POORLY-DESIGNED:DELETE}
  443. \displaythree{Standardized Operators that use Specialized Lambda Lists}{
  444. defmethod&defgeneric&\cr
  445. }
  446. % GENERIC-FUNCTION, GENERIC-FLET, and GENERIC-LABELS removed.
  447. \endissue{GENERIC-FLET-POORLY-DESIGNED:DELETE}
  448. A \term{specialized lambda list} can contain the \term{lambda list keywords} shown
  449. in \thenextfigure.
  450. \showthree{Lambda List Keywords used by Specialized Lambda Lists}{
  451. \keyref{allow-other-keys}&\keyref{key}&\keyref{rest}\cr
  452. \keyref{aux}&\keyref{optional}&\cr
  453. }
  454. A \term{specialized lambda list} is syntactically the same as an \term{ordinary lambda list}
  455. except that each \term{required parameter} may optionally be associated with a \term{class}
  456. or \term{object} for which that \term{parameter} is \term{specialized}.
  457. \Vskip 1pc!
  458. \auxbnf{lambda-list}{\lparen\star{\SpecializedVar}\CR
  459. \xparen\ttbrac{{\opt} \star{\VarValueSuppliedP}}\CR
  460. \xparen\ttbrac{{\rest} \param{var}}\CR
  461. \xparen\ttbrac{{\key} \star{\KeyVarValueSuppliedP} \brac{\allowotherkeys}}\CR
  462. \xparen\ttbrac{{\aux} \star{\VarValue}}\rparen\CR}
  463. %!!! Need to write more.
  464. \endsubSection%{Specialized Lambda Lists}
  465. \beginsubSection{Macro Lambda Lists}
  466. \DefineSection{MacroLambdaLists}
  467. A \newterm{macro lambda list} is used in describing \term{macros}
  468. defined by the \term{operators} in \thenextfigure.
  469. %!!! This table is just a seed and probably incomplete. -kmp 2-Aug-91
  470. % I added define-compiler-macro --sjl 5 Mar 92
  471. \displaythree{Operators that use Macro Lambda Lists}{
  472. define-compiler-macro&defmacro&macrolet\cr
  473. define-setf-expander& &\cr
  474. }
  475. With the additional restriction that
  476. an \term{environment parameter} may appear only once
  477. (at any of the positions indicated),
  478. a \term{macro lambda list} has the following syntax:
  479. %% Some changes here per X3J13. -kmp 05-Oct-93
  480. \Vskip 1pc!
  481. {\def\TVar{\curly{\param{var} | \down{pattern}}}\def\starTVar{\star{\TVar}}
  482. \auxbnf{reqvars}{\starTVar}
  483. \auxbnf{optvars}{\ttbrac{{\opt} \star{\VarValueSuppliedP}}}
  484. \auxbnf{restvar}{\ttbrac{\curly{{\rest} | {\body}} \param{\TVar}}}
  485. \auxbnf{keyvars}{\lbrac{\key} \star{\KeyVarValueSuppliedP}\CR
  486. \xbrac\brac{\allowotherkeys}\rbrac}
  487. {\let\TVar=\GTVar\let\starTVar=\GstarTVar%
  488. \auxbnf{auxvars}{\ttbrac{{\aux} \star{\VarValue}}}}
  489. \auxbnf{envvar}{\ttbrac{{\environment} \param{var}}}
  490. %Per X3J13 (05-Oct-93), prohibit destructuring of whole variable. -kmp
  491. \auxbnf{wholevar}{\ttbrac{{\whole} \param{var}}}
  492. \auxbnf{lambda-list}%
  493. {\lparen\down{wholevar} \down{envvar}
  494. \xparen\down{reqvars} \down{envvar}
  495. \xparen\down{optvars} \down{envvar}\CR
  496. \xparen\down{restvar} \down{envvar}
  497. \xparen\down{keyvars} \down{envvar}
  498. \xparen\down{auxvars} \down{envvar}\rparen\ |\CR
  499. \lparen\down{wholevar} \down{envvar}
  500. \xparen\down{reqvars} \down{envvar}
  501. \xparen\down{optvars} \down{envvar} \f{.}
  502. %Per x3j13, "\down{restvar}" => "var"
  503. \xparen\param{var}\rparen}
  504. \auxbnf{pattern}%
  505. {\paren{\down{wholevar}
  506. \down{reqvars}
  507. \down{optvars}
  508. \down{restvar}
  509. \down{keyvars}
  510. \down{auxvars}} |\CR
  511. \paren{\down{wholevar} \down{reqvars} \down{optvars} \f{.}
  512. %Per x3j13, "\down{restvar}" => "var"
  513. \param{var}}}
  514. }
  515. \Vskip 1pc!
  516. A \term{macro lambda list} can contain
  517. the \term{lambda list keywords} shown in \thenextfigure.
  518. \showthree{Lambda List Keywords used by Macro Lambda Lists}{
  519. \keyref{allow-other-keys}&\keyref{environment}&\keyref{rest}\cr
  520. \keyref{aux}&\keyref{key}&\keyref{whole}\cr
  521. \keyref{body}&\keyref{optional}&\cr
  522. }
  523. \term{Optional parameters} (introduced by \keyref{optional}) and
  524. \term{keyword parameters} (introduced by \keyref{key})
  525. can be supplied in a \term{macro lambda list},
  526. just as in an \term{ordinary lambda list}.
  527. Both may contain default initialization forms and \term{supplied-p parameters}.
  528. %% 8.1.0 10
  529. \keyref{body}\idxkeyref{body}
  530. is identical in function to \keyref{rest},
  531. but it can be used to inform certain output-formatting
  532. and editing functions that the remainder of the \term{form} is
  533. treated as a body, and should be indented accordingly.
  534. Only one of \keyref{body} or \keyref{rest} can be used at any particular level;
  535. \seesection\DestructuringByLambdaLists.
  536. \issue{DEFMACRO-LAMBDA-LIST:TIGHTEN-DESCRIPTION}
  537. \keyref{body} can appear at any level of a
  538. \term{macro lambda list};
  539. for details, \seesection\DestructuringByLambdaLists.
  540. \endissue{DEFMACRO-LAMBDA-LIST:TIGHTEN-DESCRIPTION}
  541. %% 8.1.0 11
  542. \keyref{whole}\idxkeyref{whole}
  543. is followed by a single variable that is bound to the
  544. entire macro-call form; this is the value that the \term{macro function}
  545. receives as its first argument.
  546. \issue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  547. %\keyref{whole} and the following variable should appear first in the \term{lambda list},
  548. If \keyref{whole} and a following variable appear,
  549. they must appear first in \param{lambda-list},
  550. \endissue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  551. before any other parameter or \term{lambda list keyword}.
  552. \issue{DEFMACRO-LAMBDA-LIST:TIGHTEN-DESCRIPTION}
  553. \keyref{whole} can appear at any level of a \term{macro lambda list}.
  554. At inner levels, the \keyref{whole} variable is bound to
  555. the corresponding part of the argument,
  556. as with \keyref{rest}, but unlike \keyref{rest}, other arguments are also allowed.
  557. The use of \keyref{whole} does not affect the pattern of arguments
  558. specified.
  559. %% Per moon
  560. %by \macref{defmacro}.
  561. \endissue{DEFMACRO-LAMBDA-LIST:TIGHTEN-DESCRIPTION}
  562. %% 8.1.0 12
  563. \keyref{environment}\idxkeyref{environment}
  564. is followed by a single variable that is bound
  565. to an \term{environment} representing the \term{lexical environment} in which the
  566. % I have clarified the bit about compilation environments below, so this
  567. % is no longer necessary. --sjl 5 Mar 92
  568. % macro call is to be interpreted---this is either the \term{lexical environment}
  569. % or the compilation \term{environment}.
  570. macro call is to be interpreted.
  571. This \term{environment}
  572. %%sandra's suggested deletion
  573. %might not be the
  574. %complete \term{lexical environment}; it
  575. should be used with
  576. \issue{MACRO-FUNCTION-ENVIRONMENT:YES}
  577. \funref{macro-function},
  578. \endissue{MACRO-FUNCTION-ENVIRONMENT:YES}
  579. \issue{GET-SETF-METHOD-ENVIRONMENT:ADD-ARG}
  580. \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  581. \funref{get-setf-expansion},
  582. \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  583. \endissue{GET-SETF-METHOD-ENVIRONMENT:ADD-ARG}
  584. \issue{SYNTACTIC-ENVIRONMENT-ACCESS:RETRACTED-MAR91}
  585. % \funref{variable-information},
  586. % \funref{function-information}, \funref{declaration-information},
  587. % \funref{augment-environment}, \funref{parse-macro}, \funref{enclose}
  588. \endissue{SYNTACTIC-ENVIRONMENT-ACCESS:RETRACTED-MAR91}
  589. \issue{DEFINE-COMPILER-MACRO:X3J13-NOV89}
  590. \funref{compiler-macro-function},
  591. %\funref{compiler-macroexpand}, \funref{compiler-macroexpand-1},
  592. \endissue{DEFINE-COMPILER-MACRO:X3J13-NOV89}
  593. and
  594. \funref{macroexpand}
  595. % !!! Sandra:
  596. % This isn't correct. Environments should also be used with things like
  597. % SUBTYPEP and CONSTANTP, and not "only" to make local macro definitions
  598. % available.
  599. % I have reworded this; see replacement text below. --sjl 5 Mar 92
  600. % for the sake of any local macro definitions
  601. % that the \specref{macrolet} \term{form} might have
  602. % established within that \term{environment}.
  603. (for example) in computing the expansion of the macro, to ensure that any
  604. \term{lexical bindings} or definitions established in the
  605. \term{compilation environment} are taken into account.
  606. \issue{DEFMACRO-LAMBDA-LIST:TIGHTEN-DESCRIPTION}
  607. \keyref{environment} can only appear at the top level of a
  608. \term{macro lambda list}, and can only
  609. appear once, but can appear anywhere in that list;
  610. \endissue{DEFMACRO-LAMBDA-LIST:TIGHTEN-DESCRIPTION}
  611. \issue{&ENVIRONMENT-BINDING-ORDER:FIRST}
  612. the \keyref{environment} \term{parameter} is \term{bound} along with \keyref{whole}
  613. before any other \term{variables} in the \term{lambda list}, regardless of where
  614. \keyref{environment} appears in the \term{lambda list}.
  615. \endissue{&ENVIRONMENT-BINDING-ORDER:FIRST}
  616. \issue{MACRO-ENVIRONMENT-EXTENT:DYNAMIC}
  617. The \term{object} that is bound to the
  618. \term{environment parameter} has \term{dynamic extent}.
  619. %% Moon: Redundant.
  620. % the consequences are undefined if
  621. % the \term{object} that is bound to the
  622. % \term{environment parameter} is referred to outside the \term{dynamic extent}
  623. % of the macro call.
  624. \endissue{MACRO-ENVIRONMENT-EXTENT:DYNAMIC}
  625. %% 8.1.0 24
  626. Destructuring allows a \term{macro lambda list} to express
  627. the structure of a macro call syntax.
  628. If no \term{lambda list keywords} appear,
  629. then the \term{macro lambda list} is a \term{tree}
  630. containing parameter names at the leaves.
  631. %The following wording revised to be more explicit. -kmp 2-Aug-91
  632. The pattern and the \term{macro form} must have compatible \term{tree structure};
  633. that is, their \term{tree structure} must be equivalent,
  634. or it must differ only in that some \term{leaves} of the pattern
  635. match \term{non-atomic} \term{objects} of the \term{macro form}.
  636. \issue{ARGUMENT-MISMATCH-ERROR-AGAIN:CONSISTENT}
  637. For information about error detection in this \term{situation},
  638. \seesection\DestructuringMismatch.
  639. \endissue{ARGUMENT-MISMATCH-ERROR-AGAIN:CONSISTENT}
  640. % I thought it was important to mention that macro lambda lists can be
  641. % dotted before talking about the restriction about dotted macro forms
  642. % below. This paragraph was formerly in its own subsection at the very
  643. % end. --sjl 5 Mar 92
  644. \DefineSection{ExtraDestructureInfo}
  645. %% 8.1.0 15
  646. %Destructuring specifies that \macref{defmacro} allows any \term{lambda list}
  647. %% For Moon:
  648. A destructuring \term{lambda list}
  649. (whether at top level or embedded)
  650. %to
  651. can
  652. be dotted, ending
  653. in a parameter name. This situation is treated exactly as if the
  654. parameter name that ends the \term{list} had appeared preceded by \keyref{rest}.
  655. %!!! Barmar suggests changing "subexpression" to "subform" here.
  656. % He writes: The point is that the automatic destructuring can only handle
  657. % dotted lists when &rest or .var are used, or when the dotted list is a subform
  658. % that matches a variable in the lambda list.
  659. \issue{DOTTED-MACRO-FORMS:ALLOW}
  660. It is permissible for a \term{macro} \term{form} (or a \term{subexpression} of a
  661. \term{macro} \term{form})
  662. to be a \term{dotted list}
  663. only when \f{(... \&rest var)} or \f{(... . var)} is used to match
  664. it. It is the responsibility of the \term{macro} to recognize and deal
  665. with such situations.
  666. \editornote{KMP: Apparently the dotted-macro-forms cleanup doesn't allow for
  667. the macro to `manually' notice dotted forms and fix them as well.
  668. It shouldn't be required that this be done only by \&REST or
  669. a dotted pattern; it should only matter that ultimately the
  670. non-macro result of a full-macro expansion not contain dots.
  671. Anyway, I plan to address this editorially unless someone
  672. raises an objection.}%!!! 16-Jan-91
  673. \endissue{DOTTED-MACRO-FORMS:ALLOW}
  674. \beginsubsubsection{Destructuring by Lambda Lists}
  675. \DefineSection{DestructuringByLambdaLists}
  676. %% 8.1.0 14
  677. % minor rewording to use new terminology -- sjl 5 Mar 92
  678. Anywhere in a \term{macro lambda list} where a parameter
  679. name can appear, and where \term{ordinary lambda list} syntax
  680. (as described in \secref\OrdinaryLambdaLists) does not
  681. otherwise allow a \term{list}, a \term{destructuring lambda list}
  682. can appear in place
  683. of the parameter name. When this is done, then the argument
  684. that would match the parameter is treated as a (possibly dotted) \term{list},
  685. to be used as an argument list for satisfying the
  686. parameters in the embedded \term{lambda list}.
  687. This is known as destructuring.
  688. %%% Moon's destructuring wording
  689. %Note that data-directed destructuring
  690. %is what Common Lisp has, and you would not want to include the parts
  691. %about program-directed destructuring, which Common Lisp has not adopted.
  692. %Lambda-list-directed destructuring is what defmacro and destructuring-bind
  693. %do in Common Lisp.
  694. Destructuring is the process of decomposing a compound \term{object} into
  695. its component parts, using an abbreviated, declarative syntax, rather
  696. than writing it out by hand using the primitive component-accessing
  697. functions. Each component part is bound to a variable.
  698. % I don't believe the following two sentences are relevant to the
  699. % current state of Common Lisp. --sjl 5 Mar 92
  700. % The variables
  701. % can either be \term{assigned} or \term{bound}. As an extension, some
  702. % component parts can be ignored and not assigned to a variable.
  703. %% KAB wanted this flushed. -kmp 9-Feb-92
  704. % Destructuring is most often used to take apart \term{trees}.
  705. % However it also makes sense to destructure \term{vectors}
  706. % and \macref{defstruct}-defined structures.
  707. % Note that in the latter case an \term{object} is being destructured
  708. % whose components are identified by name,
  709. % rather than by position as in the case of
  710. % \term{trees} and \term{vectors}.
  711. %%Barmar wanted this flushed since it isn't valid. I concur. -kmp 28-Dec-90
  712. % In fact
  713. % the idea of destructuring can sensibly be extended to compound objects
  714. % that are not primitive \term{objects} of Lisp,
  715. % but have conceptual components.
  716. % Thus a \term{rational} number can be destructured into its numerator and
  717. % denominator, a \term{two-way stream}
  718. % into its input and output components, a
  719. % byte specifier into its position and size, or
  720. % the multiple values of a \term{function} into the individual values. The
  721. % important point is that the conceptual operation of extracting several
  722. % components of a compound \term{object} is common to all of these applications.
  723. %Destructuring of \term{trees}
  724. %is especially important in programs such as macros
  725. %and compilers that manipulate Lisp code, because Lisp code is represented
  726. %as trees.
  727. A destructuring operation requires an \term{object} to be decomposed,
  728. a pattern that specifies what components are to be extracted, and the names
  729. of the variables whose values are to be the components.
  730. %% KMP: I removed this because I couldn't figure out what the non-SETQ case was.
  731. %% Seems like it was probably referring to DESETQ, which isn't in the language.
  732. % In the non-\specref{setq} case,
  733. % a destructuring operation requires a body that
  734. % constitutes the scope of the variables to be bound.
  735. \beginsubsubsubsection{Data-directed Destructuring by Lambda Lists}
  736. In data-directed destructuring,
  737. the pattern is a sample \term{object} of the \term{type} to be decomposed.
  738. Wherever a component is to be extracted,
  739. a \term{symbol} appears in the pattern;
  740. this \term{symbol} is the name of the variable whose value will be that component.
  741. %% This is just rationale, not description. -kmp 2-Aug-91
  742. % Data-directed destructuring
  743. % only works well
  744. % for \term{trees} and \term{vectors}.
  745. % The components to be extracted must be
  746. % identified by position rather than by name. Data-directed destructuring
  747. % cannot be extended to \term{objects} such as
  748. % \term{rationals} whose components
  749. % are not allowed to be \term{symbols},
  750. % and cannot be extended to conceptual
  751. % \term{objects} such as multiple values, where it is impossible to create a
  752. % sample \term{object}.
  753. \beginsubsubsubsubsection{Examples of Data-directed Destructuring by Lambda Lists}
  754. An example pattern is
  755. {\tt (a b c)}
  756. which destructures a list of three elements. The variable \f{a} is assigned
  757. to the first element, \f{b} to the second, etc. A more complex example
  758. is
  759. {\tt ((first . rest) . more)}
  760. The important features of data-directed destructuring are its syntactic
  761. simplicity and the ability to extend it to lambda-list-directed destructuring.
  762. \endsubsubsubsubsection%{Examples of Data-directed Destructuring by Lambda Lists}
  763. \endsubsubsubsection%{Data-directed Destructuring by Lambda Lists}
  764. \beginsubsubsubsection{Lambda-list-directed Destructuring by Lambda Lists}
  765. An extension of data-directed destructuring of \term{trees} is
  766. lambda-list-directed destructuring. This derives from the analogy
  767. between the three-element destructuring pattern
  768. {\tt (first second third)}
  769. and the three-argument \term{lambda list}
  770. {\tt (first second third)}
  771. %The \term{lambda list} of a function can be thought of as destructuring the
  772. %list of arguments to which the function was \term{applied}.
  773. %In most Lisp
  774. %implementations this list is only conceptual most of the time, for the
  775. %sake of efficiency.
  776. Lambda-list-directed destructuring is identical to data-directed destructuring
  777. if no \term{lambda list keywords} appear in the pattern.
  778. Any list in the pattern (whether a sub-list or the whole pattern itself)
  779. that contains a \term{lambda list keyword} is interpreted specially.
  780. Elements of the list to the left of the first
  781. \term{lambda list keyword} are treated as destructuring patterns, as usual, but the
  782. remaining elements of the list are treated like a function's
  783. \term{lambda list}
  784. except that where a variable would normally be required, an arbitrary
  785. destructuring pattern is allowed. Note that in case of ambiguity,
  786. \term{lambda list} syntax is preferred over destructuring syntax. Thus, after
  787. \keyref{optional} a list of elements is a list of a destructuring pattern
  788. and a default value form.
  789. The detailed behavior of each \term{lambda list keyword} in a
  790. lambda-list-directed destructuring
  791. pattern is as follows:
  792. \beginlist
  793. \itemitem{\keyref{optional}}
  794. Each following element is a variable or a list of a destructuring
  795. pattern, a default value form, and a supplied-p variable. The default value and
  796. the supplied-p variable can be omitted.
  797. If the list being destructured ends
  798. early, so that it does not have an element to match against this destructuring
  799. (sub)-pattern, the default form is evaluated and destructured instead. The
  800. supplied-p variable receives the value
  801. \nil\ if the default form is used, \t\ otherwise.
  802. \itemitem{\keyref{rest}, \keyref{body}}
  803. The next element is a destructuring pattern that matches the
  804. rest of the list. \keyref{body} is identical to \keyref{rest} but declares that what
  805. is being matched is a list of forms that constitutes the body of \term{form}.
  806. This next element must be the last unless a \term{lambda list keyword} follows it.
  807. \itemitem{\keyref{aux}}
  808. The remaining elements are not destructuring patterns at all, but are
  809. auxiliary variable bindings.
  810. %This does not make a whole lot of sense when
  811. %the destructuring is being used to \specref{setq} rather than to bind variables.
  812. \itemitem{\keyref{whole}}
  813. The next element is a destructuring pattern that matches the entire
  814. form in a macro, or the entire \term{subexpression} at inner levels.
  815. \issue{DEFMACRO-LAMBDA-LIST:TIGHTEN-DESCRIPTION}
  816. %% Take out next sentences due to DEFMACRO-LAMBDA-LIST
  817. %\keyref{whole} only makes sense in \macref{defmacro} and only at top level.
  818. %This next element must be the last unless a \term{lambda list keyword}
  819. %follows it.
  820. \endissue{DEFMACRO-LAMBDA-LIST:TIGHTEN-DESCRIPTION}
  821. \itemitem{\keyref{key}}
  822. Each following element is one of
  823. \beginlist
  824. \itemitem{}
  825. a \term{variable},
  826. \itemitem{or}
  827. a list of a variable,
  828. an optional initialization form,
  829. and an optional supplied-p variable.
  830. \itemitem{or}
  831. a list of a list of a keyword and a destructuring pattern,
  832. an optional initialization form,
  833. and an optional supplied-p variable.
  834. \endlist
  835. The rest of the list being destructured
  836. is taken to be alternating keywords and values and is taken apart appropriately.
  837. \itemitem{\keyref{allow-other-keys}}
  838. Stands by itself.
  839. \endlist
  840. %{--- The above has some terminology problems. The distinction between the
  841. %list which is a sub-list of the pattern and the corresponding sub-list of
  842. %the object being destructured is muddled in places.}
  843. \endsubsubsubsection%{Lambda-list-directed Destructuring by Lambda Lists}
  844. % \beginsubsubsubsection{Additional Information about Destructuring by Lambda Lists}
  845. % \DefineSection{ExtraDestructureInfo}
  846. % I moved the text about dotted lambda lists to earlier in this section.
  847. % -- sjl 5 Mar 92
  848. % \endsubsubsubsection%{Additional Information about Destructuring by Lambda Lists}
  849. \endsubsubsection%{Destructuring by Lambda Lists}
  850. \endsubSection%{Macro Lambda Lists}
  851. % This entire section is new. --sjl 5 Mar 92
  852. \beginsubsection{Destructuring Lambda Lists}
  853. \DefineSection{DestructuringLambdaLists}
  854. A \newterm{destructuring lambda list} is used by \macref{destructuring-bind}.
  855. \term{Destructuring lambda lists} are closely related to
  856. \term{macro lambda lists}; \seesection\MacroLambdaLists.
  857. A \term{destructuring lambda list} can contain all of the
  858. \term{lambda list keywords} listed for \term{macro lambda lists}
  859. except for \keyref{environment}, and supports destructuring in the
  860. same way. Inner \term{lambda lists} nested within a \term{macro lambda list}
  861. have the syntax of \term{destructuring lambda lists}.
  862. A \term{destructuring lambda list} has the following syntax:
  863. \Vskip 1pc!
  864. {\def\TVar{\curly{\param{var} | \down{lambda-list}}}\def\starTVar{\star{\TVar}}
  865. \auxbnf{reqvars}{\starTVar}
  866. \auxbnf{optvars}{\ttbrac{{\opt} \star{\VarValueSuppliedP}}}
  867. \auxbnf{restvar}{\ttbrac{\curly{{\rest} | {\body}} \param{\TVar}}}
  868. \auxbnf{keyvars}{\lbrac{\key} \star{\KeyVarValueSuppliedP}\CR
  869. \xbrac\brac{\allowotherkeys}\rbrac}
  870. {\let\TVar=\GTVar\let\starTVar=\GstarTVar%
  871. \auxbnf{auxvars}{\ttbrac{{\aux} \star{\VarValue}}}}
  872. \auxbnf{envvar}{\ttbrac{{\environment} \param{var}}}
  873. %Per X3J13 (05-Oct-93), prohibit destructuring of whole variable. -kmp
  874. \auxbnf{wholevar}{\ttbrac{{\whole} \param{var}}}
  875. \auxbnf{lambda-list}%
  876. {\paren{\down{wholevar}
  877. \down{reqvars}
  878. \down{optvars}
  879. \down{restvar}
  880. \down{keyvars}
  881. \down{auxvars}} |\CR
  882. \paren{\down{wholevar} \down{reqvars} \down{optvars} \f{.}
  883. %Per x3j13, "\down{restvar}" => "var"
  884. \param{var}}}
  885. }
  886. \Vskip 1pc!
  887. \endsubsection%{Destructuring Lambda Lists}
  888. \beginsubsection{Boa Lambda Lists}
  889. \DefineSection{BoaLambdaLists}
  890. A \newterm{boa lambda list} is a \term{lambda list} that is syntactically
  891. like an \term{ordinary lambda list}, but that is processed in
  892. ``\b{b}y \b{o}rder of \b{a}rgument'' style.
  893. A \term{boa lambda list} is used only in a \macref{defstruct} \term{form},
  894. when explicitly specifying the \term{lambda list}
  895. of a constructor \term{function} (sometimes called a ``boa constructor'').
  896. %% 19.6.0 2
  897. The \keyref{optional}, \keyref{rest}, \keyref{aux},
  898. \issue{DEFSTRUCT-CONSTRUCTOR-KEY-MIXTURE:ALLOW-KEY}
  899. \keyref{key}, and \keyref{allow-other-keys}
  900. \endissue{DEFSTRUCT-CONSTRUCTOR-KEY-MIXTURE:ALLOW-KEY}
  901. \term{lambda list keywords} are recognized in a \term{boa lambda list}.
  902. The way these \term{lambda list keywords} differ from their
  903. use in an \term{ordinary lambda list} follows.
  904. Consider this example, which describes how \macref{destruct} processes
  905. its \kwd{constructor} option.
  906. \code
  907. (:constructor create-foo
  908. (a &optional b (c 'sea) &rest d &aux e (f 'eff)))
  909. \endcode
  910. This defines \f{create-foo} to be a constructor of one or more arguments.
  911. The first argument is used to initialize the \f{a} slot. The second
  912. argument is used to initialize the \f{b} slot. If there isn't any
  913. second argument, then the default value given in the body of the
  914. \macref{defstruct} (if given) is used instead.
  915. The third argument is used to
  916. initialize the \f{c} slot. If there isn't any third argument, then the
  917. symbol \f{sea} is used instead. Any arguments following the third
  918. argument are collected into a \term{list}
  919. and used to initialize the \f{d}
  920. slot. If there are three or fewer arguments, then \nil\ is placed in
  921. the \f{d} slot. The \f{e} slot is not initialized;
  922. its initial value is \term{implementation-defined}.
  923. Finally, the \f{f} slot is initialized to contain the symbol \f{eff}.
  924. \issue{DEFSTRUCT-CONSTRUCTOR-KEY-MIXTURE:ALLOW-KEY}
  925. \keyref{key} and \keyref{allow-other-keys} arguments default
  926. in a manner similar to that of \keyref{optional} arguments: if no default
  927. is supplied in the \term{lambda list} then the default value
  928. given in the body of the \macref{defstruct} (if given) is used instead.
  929. %% Removed per Moon as redundant.
  930. % then the slot initform is used;
  931. % otherwise the slot is not initialized, its initial value is
  932. % undefined.
  933. For example:
  934. \code
  935. (defstruct (foo (:constructor CREATE-FOO (a &optional b (c 'sea)
  936. &key (d 2)
  937. &aux e (f 'eff))))
  938. (a 1) (b 2) (c 3) (d 4) (e 5) (f 6))
  939. (create-foo 10) \EV #S(FOO A 10 B 2 C SEA D 2 E \term{implemention-dependent} F EFF)
  940. (create-foo 10 'bee 'see :d 'dee)
  941. \EV #S(FOO A 10 B BEE C SEE D DEE E \term{implemention-dependent} F EFF)
  942. \endcode
  943. If keyword arguments of the form
  944. \f{((\i{key} \i{var}) \brac{\i{default} \brac{\i{svar}}})}
  945. are specified, the \term{slot} \term{name} is matched with \i{var}
  946. (not \i{key}).
  947. %% 19.6.0 3
  948. The actions taken in the \f{b} and \f{e} cases were carefully
  949. chosen to allow the user to specify all possible behaviors.
  950. The \keyref{aux} variables can be used to completely override the default
  951. initializations given in the body.
  952. \issue{BOA-AUX-INITIALIZATION:ERROR-ON-READ}
  953. If no default value is supplied for an \term{aux variable} variable,
  954. the consequences are undefined if an attempt is later made to read
  955. the corresponding \term{slot}'s value before a value is explicitly assigned.
  956. If such a \term{slot} has a \kwd{type} option specified,
  957. this suppressed initialization does not imply a type mismatch situation;
  958. the declared type is only required to apply when the \term{slot} is finally assigned.
  959. \endissue{BOA-AUX-INITIALIZATION:ERROR-ON-READ}
  960. %% 19.6.0 4
  961. With this definition, the following can be written:
  962. \code
  963. (create-foo 1 2)
  964. \endcode
  965. instead of
  966. \code
  967. (make-foo :a 1 :b 2)
  968. \endcode
  969. and \f{create-foo} provides defaulting different
  970. from that of \f{make-foo}.
  971. Additional arguments that do not correspond to slot names but
  972. are merely present to supply values used in subsequent initialization
  973. computations are allowed.
  974. For example, in the definition
  975. \code
  976. (defstruct (frob (:constructor create-frob
  977. (a &key (b 3 have-b) (c-token 'c)
  978. (c (list c-token (if have-b 7 2))))))
  979. a b c)
  980. \endcode
  981. the {\tt c-token} argument is used merely to supply a value used in the
  982. initialization of the {\tt c} slot. The \term{supplied-p parameters}
  983. associated with \term{optional parameters} and \term{keyword parameters}
  984. might also be used this way.
  985. \endissue{DEFSTRUCT-CONSTRUCTOR-KEY-MIXTURE:ALLOW-KEY}
  986. \endsubsection%{Boa Lambda Lists}
  987. \beginsubSection{Defsetf Lambda Lists}
  988. \DefineSection{DefsetfLambdaLists}
  989. A \newterm{defsetf lambda list} is used by \macref{defsetf}.
  990. A \term{defsetf lambda list} has the following syntax:
  991. %I added &allow-other-keys here because it seemed stupid for that to be missing
  992. %if &key was possible.
  993. \Vskip 1pc!
  994. \auxbnf{lambda-list}{\lparen\starparam{var}\CR
  995. \xparen\ttbrac{{\opt} \star{\VarValueSuppliedP}}\CR
  996. \xparen\ttbrac{{\rest} \param{var}}\CR
  997. \xparen\f{[}\Vtop{\hbox{{\key} \star{\KeyVarValueSuppliedP}}
  998. \vskip 4pt
  999. \hbox{\brac{\allowotherkeys}\f{]}}}\CR
  1000. \xparen\ttbrac{{\environment} \param{var}}}
  1001. A \term{defsetf lambda list} can contain the \term{lambda list keywords} shown
  1002. in \thenextfigure.
  1003. %I also added &environment, per discussion with Sandra and Quinquevirate.
  1004. \showthree{Lambda List Keywords used by Defsetf Lambda Lists}{
  1005. \keyref{allow-other-keys}&\keyref{key}&\keyref{rest}\cr
  1006. \keyref{environment}&\keyref{optional}&\cr
  1007. }
  1008. A \term{defsetf lambda list} differs from an \term{ordinary lambda list}
  1009. only in that it does not permit the use of \keyref{aux},
  1010. and that it permits use of \keyref{environment},
  1011. which introduces an \term{environment parameter}.
  1012. \endsubSection%{Defsetf Lambda Lists}
  1013. \beginsubSection{Deftype Lambda Lists}
  1014. \DefineSection{DeftypeLambdaLists}
  1015. A \newterm{deftype lambda list} is used by \macref{deftype}.
  1016. A \term{deftype lambda list} has the same syntax as a \term{macro lambda list},
  1017. and can therefore contain the \term{lambda list keywords} as a \term{macro lambda list}.
  1018. \issue{DEFTYPE-DESTRUCTURING:YES}
  1019. \issue{DEFTYPE-KEY:ALLOW}
  1020. A \term{deftype lambda list} differs from a \term{macro lambda list}
  1021. only in that if no \param{init-form} is supplied for an \term{optional parameter}
  1022. or \term{keyword parameter} in the \param{lambda-list}, the default \term{value}
  1023. for that \term{parameter} is the \term{symbol} \misc{*} (rather than \nil).
  1024. \endissue{DEFTYPE-KEY:ALLOW}
  1025. \endissue{DEFTYPE-DESTRUCTURING:YES}
  1026. \endsubSection%{Deftype Lambda Lists}
  1027. % This entire section is new. Some info paraphrased from the
  1028. % old dictionary entry for define-modify-macro. --sjl 5 Mar 92
  1029. \beginsubsection{Define-modify-macro Lambda Lists}
  1030. \DefineSection{DefineModifyMacroLambdaLists}
  1031. A \newterm{define-modify-macro lambda list} is used by
  1032. \macref{define-modify-macro}.
  1033. A \term{define-modify-macro lambda list} can contain the
  1034. \term{lambda list keywords} shown in \thenextfigure.
  1035. \showtwo{Lambda List Keywords used by Define-modify-macro Lambda Lists}{
  1036. \keyref{optional}&\keyref{rest}\cr
  1037. }
  1038. \term{Define-modify-macro lambda lists} are similar to
  1039. \term{ordinary lambda lists}, but do not support keyword arguments.
  1040. \macref{define-modify-macro} has no need match keyword arguments, and
  1041. a \term{rest parameter} is sufficient. \term{Aux variables} are also
  1042. not supported, since \macref{define-modify-macro} has no body \term{forms}
  1043. which could refer to such \term{bindings}. \Seemac{define-modify-macro}.
  1044. \endsubsection%{Define-modify-macro Lambda Lists}
  1045. % This entire section is new, per Barrett #3 (first public review).
  1046. \beginsubsection{Define-method-combination Arguments Lambda Lists}
  1047. \DefineSection{DefMethCombArgsLambdaLists}
  1048. A \newterm{define-method-combination arguments lambda list} is used by
  1049. the \kwd{arguments} option to \macref{define-method-combination}.
  1050. A \term{define-method-combination arguments lambda list} can contain the
  1051. \term{lambda list keywords} shown in \thenextfigure.
  1052. \showthree{Lambda List Keywords used by Define-method-combination arguments Lambda Lists}{
  1053. \keyref{allow-other-keys}&\keyref{key}&\keyref{rest}\cr
  1054. \keyref{aux}&\keyref{optional}&\keyref{whole}\cr
  1055. }
  1056. \term{Define-method-combination arguments lambda lists} are similar to
  1057. \term{ordinary lambda lists}, but also permit the use of \keyref{whole}.
  1058. \endsubsection%{Define-Modify-Macro Arguments Lambda Lists}
  1059. \beginsubsection{Syntactic Interaction of Documentation Strings and Declarations}
  1060. \DefineSection{DocVsDecls}
  1061. %% 8.1.0 8
  1062. In a number of situations, a \term{documentation string} can appear amidst a
  1063. series of \misc{declare} \term{expressions} prior to a series of \term{forms}.
  1064. In that case, if a \term{string} $S$ appears where a \term{documentation string} is
  1065. permissible and is not followed by
  1066. either a \misc{declare} \term{expression}
  1067. or a \term{form}
  1068. then $S$ is taken to be a \term{form};
  1069. otherwise, $S$ is taken as a \term{documentation string}.
  1070. The consequences are unspecified if more than one such \term{documentation string}
  1071. is present.
  1072. \endsubsection%{Syntactic Interaction of Documentation Strings and Declarations}