My various dotfiles

chap-17.texi 77KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269
  1. @node Sequences, Hash Tables, Strings, Top
  2. @chapter Sequences
  3. @menu
  4. * Sequence Concepts::
  5. * Rules about Test Functions::
  6. * Sequences Dictionary::
  7. @end menu
  8. @node Sequence Concepts, Rules about Test Functions, Sequences, Sequences
  9. @section Sequence Concepts
  10. @c including concept-sequences
  11. A @i{sequence}
  12. @IGindex{sequence}
  13. is an ordered collection of @i{elements},
  14. implemented as either a @i{vector} or a @i{list}.
  15. @i{Sequences} can be created by the @i{function} @b{make-sequence},
  16. as well as other @i{functions} that create @i{objects}
  17. of @i{types} that are @i{subtypes} of @b{sequence}
  18. (@i{e.g.}, @b{list}, @b{make-list}, @b{mapcar}, and @b{vector}).
  19. A @i{sequence function}
  20. @IGindex{sequence function}
  21. is a @i{function}
  22. defined by this specification
  23. or added as an extension by the @i{implementation}
  24. that operates on one or more @i{sequences}.
  25. Whenever a @i{sequence function} must construct and return
  26. a new @i{vector}, it always returns a @i{simple vector}.
  27. Similarly, any @i{strings} constructed will be @i{simple strings}.
  28. @group
  29. @noindent
  30. @w{ concatenate length remove }
  31. @w{ copy-seq map remove-duplicates }
  32. @w{ count map-into remove-if }
  33. @w{ count-if merge remove-if-not }
  34. @w{ count-if-not mismatch replace }
  35. @w{ delete notany reverse }
  36. @w{ delete-duplicates notevery search }
  37. @w{ delete-if nreverse some }
  38. @w{ delete-if-not nsubstitute sort }
  39. @w{ elt nsubstitute-if stable-sort }
  40. @w{ every nsubstitute-if-not subseq }
  41. @w{ fill position substitute }
  42. @w{ find position-if substitute-if }
  43. @w{ find-if position-if-not substitute-if-not }
  44. @w{ find-if-not reduce }
  45. @noindent
  46. @w{ Figure 17--1: Standardized Sequence Functions }
  47. @end group
  48. @menu
  49. * General Restrictions on Parameters that must be Sequences::
  50. @end menu
  51. @node General Restrictions on Parameters that must be Sequences, , Sequence Concepts, Sequence Concepts
  52. @subsection General Restrictions on Parameters that must be Sequences
  53. In general, @i{lists} (including @i{association lists} and @i{property lists})
  54. that are treated as @i{sequences} must be @i{proper lists}.
  55. @c end of including concept-sequences
  56. @node Rules about Test Functions, Sequences Dictionary, Sequence Concepts, Sequences
  57. @section Rules about Test Functions
  58. @c including concept-tests
  59. @menu
  60. * Satisfying a Two-Argument Test::
  61. * Satisfying a One-Argument Test::
  62. @end menu
  63. @node Satisfying a Two-Argument Test, Satisfying a One-Argument Test, Rules about Test Functions, Rules about Test Functions
  64. @subsection Satisfying a Two-Argument Test
  65. When an @i{object} O is being considered iteratively
  66. against each @i{element} E_i
  67. of a @i{sequence} S
  68. by an @i{operator} F listed in Figure 17--2,
  69. it is sometimes useful to control the way in which the presence of O
  70. is tested in S is tested by F.
  71. This control is offered on the basis of a @i{function} designated with
  72. either a @t{:test} or @t{:test-not} @i{argument}.
  73. @group
  74. @noindent
  75. @w{ adjoin nset-exclusive-or search }
  76. @w{ assoc nsublis set-difference }
  77. @w{ count nsubst set-exclusive-or }
  78. @w{ delete nsubstitute sublis }
  79. @w{ find nunion subsetp }
  80. @w{ intersection position subst }
  81. @w{ member pushnew substitute }
  82. @w{ mismatch rassoc tree-equal }
  83. @w{ nintersection remove union }
  84. @w{ nset-difference remove-duplicates }
  85. @noindent
  86. @w{ Figure 17--2: Operators that have Two-Argument Tests to be Satisfied}
  87. @end group
  88. The object O might not be compared directly to E_i.
  89. If a @t{:key} @i{argument} is provided,
  90. it is a @i{designator} for a @i{function} of one @i{argument}
  91. to be called with each E_i as an @i{argument},
  92. and @i{yielding} an @i{object} Z_i to be used for comparison.
  93. (If there is no @t{:key} @i{argument}, Z_i is E_i.)
  94. The @i{function} designated by the @t{:key} @i{argument} is never called on O itself.
  95. However, if the function operates on multiple sequences
  96. (@i{e.g.}, as happens in @b{set-difference}), O
  97. will be the result of calling the @t{:key} function on an
  98. @i{element} of the other sequence.
  99. A @t{:test} @i{argument}, if supplied to F,
  100. is a @i{designator} for a @i{function}
  101. of two @i{arguments}, O and Z_i.
  102. An E_i is said (or, sometimes, an O and an E_i are said)
  103. to @i{satisfy the test}
  104. @IGindex{satisfy the test}
  105. if this @t{:test} @i{function} returns a @i{generalized boolean} representing
  106. @i{true}.
  107. A @t{:test-not} @i{argument}, if supplied to F,
  108. is @i{designator} for a @i{function}
  109. of two @i{arguments}, O and Z_i.
  110. An E_i is said (or, sometimes, an O and an E_i are said)
  111. to @i{satisfy the test}
  112. @IGindex{satisfy the test}
  113. if this @t{:test-not} @i{function}
  114. returns a @i{generalized boolean} representing @i{false}.
  115. If neither a @t{:test} nor a @t{:test-not} @i{argument} is supplied,
  116. it is as if a @t{:test} argument of @t{#'eql} was supplied.
  117. The consequences are unspecified if both a @t{:test} and a @t{:test-not} @i{argument}
  118. are supplied in the same @i{call} to F.
  119. @menu
  120. * Examples of Satisfying a Two-Argument Test::
  121. @end menu
  122. @node Examples of Satisfying a Two-Argument Test, , Satisfying a Two-Argument Test, Satisfying a Two-Argument Test
  123. @subsubsection Examples of Satisfying a Two-Argument Test
  124. @example
  125. (remove "FOO" '(foo bar "FOO" "BAR" "foo" "bar") :test #'equal)
  126. @result{} (foo bar "BAR" "foo" "bar")
  127. (remove "FOO" '(foo bar "FOO" "BAR" "foo" "bar") :test #'equalp)
  128. @result{} (foo bar "BAR" "bar")
  129. (remove "FOO" '(foo bar "FOO" "BAR" "foo" "bar") :test #'string-equal)
  130. @result{} (bar "BAR" "bar")
  131. (remove "FOO" '(foo bar "FOO" "BAR" "foo" "bar") :test #'string=)
  132. @result{} (BAR "BAR" "foo" "bar")
  133. (remove 1 '(1 1.0 #C(1.0 0.0) 2 2.0 #C(2.0 0.0)) :test-not #'eql)
  134. @result{} (1)
  135. (remove 1 '(1 1.0 #C(1.0 0.0) 2 2.0 #C(2.0 0.0)) :test-not #'=)
  136. @result{} (1 1.0 #C(1.0 0.0))
  137. (remove 1 '(1 1.0 #C(1.0 0.0) 2 2.0 #C(2.0 0.0)) :test (complement #'=))
  138. @result{} (1 1.0 #C(1.0 0.0))
  139. (count 1 '((one 1) (uno 1) (two 2) (dos 2)) :key #'cadr) @result{} 2
  140. (count 2.0 '(1 2 3) :test #'eql :key #'float) @result{} 1
  141. (count "FOO" (list (make-pathname :name "FOO" :type "X")
  142. (make-pathname :name "FOO" :type "Y"))
  143. :key #'pathname-name
  144. :test #'equal)
  145. @result{} 2
  146. @end example
  147. @node Satisfying a One-Argument Test, , Satisfying a Two-Argument Test, Rules about Test Functions
  148. @subsection Satisfying a One-Argument Test
  149. When using one of the @i{functions} in Figure 17--3,
  150. the elements E of a @i{sequence} S are filtered
  151. not on the basis of the presence or absence of an object O
  152. under a two @i{argument} @i{predicate},
  153. as with the @i{functions} described in @ref{Satisfying a Two-Argument Test},
  154. but rather on the basis of a one @i{argument} @i{predicate}.
  155. @group
  156. @noindent
  157. @w{ assoc-if member-if rassoc-if }
  158. @w{ assoc-if-not member-if-not rassoc-if-not }
  159. @w{ count-if nsubst-if remove-if }
  160. @w{ count-if-not nsubst-if-not remove-if-not }
  161. @w{ delete-if nsubstitute-if subst-if }
  162. @w{ delete-if-not nsubstitute-if-not subst-if-not }
  163. @w{ find-if position-if substitute-if }
  164. @w{ find-if-not position-if-not substitute-if-not }
  165. @noindent
  166. @w{ Figure 17--3: Operators that have One-Argument Tests to be Satisfied}
  167. @end group
  168. The element E_i might not be considered directly.
  169. If a @t{:key} @i{argument} is provided,
  170. it is a @i{designator} for a @i{function} of one @i{argument}
  171. to be called with each E_i as an @i{argument},
  172. and @i{yielding} an @i{object} Z_i to be used for comparison.
  173. (If there is no @t{:key} @i{argument}, Z_i is E_i.)
  174. @i{Functions} defined in this specification and having a name that
  175. ends in ``@t{-if}'' accept a first @i{argument} that is a @i{designator} for a
  176. @i{function} of one @i{argument}, Z_i.
  177. An E_i is said to @i{satisfy the test}
  178. @IGindex{satisfy the test}
  179. if this @t{:test} @i{function}
  180. returns a @i{generalized boolean} representing @i{true}.
  181. @i{Functions} defined in this specification and having a name that
  182. ends in ``@t{-if-not}'' accept a first @i{argument} that is a @i{designator} for a
  183. @i{function} of one @i{argument}, Z_i.
  184. An E_i is said to @i{satisfy the test}
  185. @IGindex{satisfy the test}
  186. if this @t{:test} @i{function}
  187. returns a @i{generalized boolean} representing @i{false}.
  188. @menu
  189. * Examples of Satisfying a One-Argument Test::
  190. @end menu
  191. @node Examples of Satisfying a One-Argument Test, , Satisfying a One-Argument Test, Satisfying a One-Argument Test
  192. @subsubsection Examples of Satisfying a One-Argument Test
  193. @example
  194. (count-if #'zerop '(1 #C(0.0 0.0) 0 0.0d0 0.0s0 3)) @result{} 4
  195. (remove-if-not #'symbolp '(0 1 2 3 4 5 6 7 8 9 A B C D E F))
  196. @result{} (A B C D E F)
  197. (remove-if (complement #'symbolp) '(0 1 2 3 4 5 6 7 8 9 A B C D E F))
  198. @result{} (A B C D E F)
  199. (count-if #'zerop '("foo" "" "bar" "" "" "baz" "quux") :key #'length)
  200. @result{} 3
  201. @end example
  202. @c end of including concept-tests
  203. @node Sequences Dictionary, , Rules about Test Functions, Sequences
  204. @section Sequences Dictionary
  205. @c including dict-sequences
  206. @menu
  207. * sequence::
  208. * copy-seq::
  209. * elt::
  210. * fill::
  211. * make-sequence::
  212. * subseq::
  213. * map::
  214. * map-into::
  215. * reduce::
  216. * count::
  217. * length::
  218. * reverse::
  219. * sort::
  220. * find::
  221. * position::
  222. * search::
  223. * mismatch::
  224. * replace::
  225. * substitute::
  226. * concatenate::
  227. * merge::
  228. * remove::
  229. * remove-duplicates::
  230. @end menu
  231. @node sequence, copy-seq, Sequences Dictionary, Sequences Dictionary
  232. @subsection sequence [System Class]
  233. @subsubheading Class Precedence List::
  234. @b{sequence},
  235. @b{t}
  236. @subsubheading Description::
  237. @i{Sequences} are ordered collections of @i{objects},
  238. called the @i{elements} of the @i{sequence}.
  239. The @i{types} @b{vector} and the @i{type} @b{list} are @i{disjoint} @i{subtypes} of @i{type} @b{sequence},
  240. but are not necessarily an @i{exhaustive partition} of @i{sequence}.
  241. When viewing a @i{vector} as a @i{sequence},
  242. only the @i{active} @i{elements} of that @i{vector}
  243. are considered @i{elements} of the @i{sequence};
  244. that is,
  245. @i{sequence} operations respect the @i{fill pointer}
  246. when given @i{sequences} represented as @i{vectors}.
  247. @node copy-seq, elt, sequence, Sequences Dictionary
  248. @subsection copy-seq [Function]
  249. @code{copy-seq} @i{sequence} @result{} @i{copied-sequence}
  250. @subsubheading Arguments and Values::
  251. @i{sequence}---a @i{proper sequence}.
  252. @i{copied-sequence}---a @i{proper sequence}.
  253. @subsubheading Description::
  254. Creates a copy of @i{sequence}. The @i{elements} of the new
  255. @i{sequence} are the @i{same} as the corresponding @i{elements} of
  256. the given @i{sequence}.
  257. If @i{sequence} is a @i{vector},
  258. the result is a @i{fresh} @i{simple array}
  259. of @i{rank} one
  260. that has the same @i{actual array element type} as @i{sequence}.
  261. If @i{sequence} is a @i{list},
  262. the result is a @i{fresh} @i{list}.
  263. @subsubheading Examples::
  264. @example
  265. (setq str "a string") @result{} "a string"
  266. (equalp str (copy-seq str)) @result{} @i{true}
  267. (eql str (copy-seq str)) @result{} @i{false}
  268. @end example
  269. @subsubheading Exceptional Situations::
  270. Should be prepared to signal an error of @i{type} @b{type-error}
  271. if @i{sequence} is not a @i{proper sequence}.
  272. @subsubheading See Also::
  273. @ref{copy-list}
  274. @subsubheading Notes::
  275. From a functional standpoint,
  276. @example
  277. (copy-seq x) @equiv{} (subseq x 0)
  278. @end example
  279. However, the programmer intent is typically very different in these two cases.
  280. @node elt, fill, copy-seq, Sequences Dictionary
  281. @subsection elt [Accessor]
  282. @code{elt} @i{sequence index} @result{} @i{object}
  283. (setf (@code{ elt} @i{sequence index}) new-object)@*
  284. @subsubheading Arguments and Values::
  285. @i{sequence}---a @i{proper sequence}.
  286. @i{index}---a @i{valid sequence index} for @i{sequence}.
  287. @i{object}---an @i{object}.
  288. @i{new-object}---an @i{object}.
  289. @subsubheading Description::
  290. @i{Accesses} the @i{element} of @i{sequence} specified by @i{index}.
  291. @subsubheading Examples::
  292. @example
  293. (setq str (copy-seq "0123456789")) @result{} "0123456789"
  294. (elt str 6) @result{} #\6
  295. (setf (elt str 0) #\#) @result{} #\#
  296. str @result{} "#123456789"
  297. @end example
  298. @subsubheading Exceptional Situations::
  299. Should be prepared to signal an error of @i{type} @b{type-error}
  300. if @i{sequence} is not a @i{proper sequence}.
  301. Should signal an error of @i{type} @b{type-error}
  302. if @i{index} is not a @i{valid sequence index} for @i{sequence}.
  303. @subsubheading See Also::
  304. @ref{aref}
  305. ,
  306. @ref{nth}
  307. ,
  308. @ref{Compiler Terminology}
  309. @subsubheading Notes::
  310. @b{aref} may be used to @i{access} @i{vector}
  311. elements that are beyond the @i{vector}'s @i{fill pointer}.
  312. @node fill, make-sequence, elt, Sequences Dictionary
  313. @subsection fill [Function]
  314. @code{fill} @i{sequence item {&key} start end} @result{} @i{sequence}
  315. @subsubheading Arguments and Values::
  316. @i{sequence}---a @i{proper sequence}.
  317. @i{item}---a @i{sequence}.
  318. @i{start}, @i{end}---@i{bounding index designators} of @i{sequence}.
  319. The defaults for @i{start} and @i{end} are @t{0} and @b{nil}, respectively.
  320. @subsubheading Description::
  321. Replaces the @i{elements} of @i{sequence}
  322. @i{bounded} by @i{start} and @i{end}
  323. with @i{item}.
  324. @subsubheading Examples::
  325. @example
  326. (fill (list 0 1 2 3 4 5) '(444)) @result{} ((444) (444) (444) (444) (444) (444))
  327. (fill (copy-seq "01234") #\e :start 3) @result{} "012ee"
  328. (setq x (vector 'a 'b 'c 'd 'e)) @result{} #(A B C D E)
  329. (fill x 'z :start 1 :end 3) @result{} #(A Z Z D E)
  330. x @result{} #(A Z Z D E)
  331. (fill x 'p) @result{} #(P P P P P)
  332. x @result{} #(P P P P P)
  333. @end example
  334. @subsubheading Side Effects::
  335. @i{Sequence} is destructively modified.
  336. @subsubheading Exceptional Situations::
  337. Should be prepared to signal an error of @i{type} @b{type-error}
  338. if @i{sequence} is not a @i{proper sequence}.
  339. Should signal an error of @i{type} @b{type-error}
  340. if @i{start} is not a non-negative @i{integer}.
  341. Should signal an error of @i{type} @b{type-error}
  342. if @i{end} is not a non-negative @i{integer} or @b{nil}.
  343. @subsubheading See Also::
  344. @ref{replace}
  345. , @b{nsubstitute}
  346. @subsubheading Notes::
  347. @t{(fill @i{sequence} @i{item}) @equiv{}
  348. (nsubstitute-if @i{item} (constantly t) @i{sequence})}
  349. @node make-sequence, subseq, fill, Sequences Dictionary
  350. @subsection make-sequence [Function]
  351. @code{make-sequence} @i{result-type size {&key} initial-element} @result{} @i{sequence}
  352. @subsubheading Arguments and Values::
  353. @i{result-type}---a @b{sequence} @i{type specifier}.
  354. @i{size}---a non-negative @i{integer}.
  355. @i{initial-element}---an @i{object}.
  356. The default is @i{implementation-dependent}.
  357. @i{sequence}---a @i{proper sequence}.
  358. @subsubheading Description::
  359. Returns a @i{sequence} of the type @i{result-type} and of length @i{size},
  360. each of the @i{elements} of which has been initialized to @i{initial-element}.
  361. If the @i{result-type} is a @i{subtype} of @b{list},
  362. the result will be a @i{list}.
  363. If the @i{result-type} is a @i{subtype} of @b{vector},
  364. then if the implementation can determine the element type specified
  365. for the @i{result-type}, the element type of the resulting array
  366. is the result of @i{upgrading} that element type; or, if the
  367. implementation can determine that the element type is unspecified (or @t{*}),
  368. the element type of the resulting array is @b{t};
  369. otherwise, an error is signaled.
  370. @subsubheading Examples::
  371. @example
  372. (make-sequence 'list 0) @result{} ()
  373. (make-sequence 'string 26 :initial-element #\.)
  374. @result{} ".........................."
  375. (make-sequence '(vector double-float) 2
  376. :initial-element 1d0)
  377. @result{} #(1.0d0 1.0d0)
  378. @end example
  379. @example
  380. (make-sequence '(vector * 2) 3) should signal an error
  381. (make-sequence '(vector * 4) 3) should signal an error
  382. @end example
  383. @subsubheading Affected By::
  384. The @i{implementation}.
  385. @subsubheading Exceptional Situations::
  386. The consequences are unspecified if @i{initial-element}
  387. is not an @i{object} which can be stored in the resulting @i{sequence}.
  388. An error of @i{type} @b{type-error} must be signaled if the @i{result-type} is neither
  389. a @i{recognizable subtype} of @b{list},
  390. nor a @i{recognizable subtype} of @b{vector}.
  391. An error of @i{type} @b{type-error} should be signaled if @i{result-type} specifies
  392. the number of elements and @i{size} is different from that number.
  393. @subsubheading See Also::
  394. @ref{make-array}
  395. ,
  396. @ref{make-list}
  397. @subsubheading Notes::
  398. @example
  399. (make-sequence 'string 5) @equiv{} (make-string 5)
  400. @end example
  401. @node subseq, map, make-sequence, Sequences Dictionary
  402. @subsection subseq [Accessor]
  403. @code{subseq} @i{sequence start {&optional} end} @result{} @i{subsequence}
  404. (setf (@code{ subseq} @i{sequence start {&optional} end}) new-subsequence)@*
  405. @subsubheading Arguments and Values::
  406. @i{sequence}---a @i{proper sequence}.
  407. @i{start}, @i{end}---@i{bounding index designators} of @i{sequence}.
  408. The default for @i{end} is @b{nil}.
  409. @i{subsequence}---a @i{proper sequence}.
  410. @i{new-subsequence}---a @i{proper sequence}.
  411. @subsubheading Description::
  412. @b{subseq} creates a @i{sequence}
  413. that is a copy of the subsequence of @i{sequence}
  414. @i{bounded} by @i{start} and @i{end}.
  415. @i{Start} specifies an offset into the original @i{sequence} and
  416. marks the beginning position of the subsequence.
  417. @i{end} marks the position following the last element of the subsequence.
  418. @b{subseq} always allocates a new @i{sequence} for a result;
  419. it never shares storage with an old @i{sequence}.
  420. The result subsequence is always of the same @i{type} as @i{sequence}.
  421. If @i{sequence} is a @i{vector},
  422. the result is a @i{fresh} @i{simple array}
  423. of @i{rank} one
  424. that has the same @i{actual array element type} as @i{sequence}.
  425. If @i{sequence} is a @i{list},
  426. the result is a @i{fresh} @i{list}.
  427. @b{setf} may be used with @b{subseq} to destructively replace
  428. @i{elements} of a subsequence with @i{elements}
  429. taken from a @i{sequence} of new values.
  430. If the subsequence and the new sequence are not of equal length,
  431. the shorter length determines the number of elements that are
  432. replaced. The remaining @i{elements} at the end of the longer sequence
  433. are not modified in the operation.
  434. @subsubheading Examples::
  435. @example
  436. (setq str "012345") @result{} "012345"
  437. (subseq str 2) @result{} "2345"
  438. (subseq str 3 5) @result{} "34"
  439. (setf (subseq str 4) "abc") @result{} "abc"
  440. str @result{} "0123ab"
  441. (setf (subseq str 0 2) "A") @result{} "A"
  442. str @result{} "A123ab"
  443. @end example
  444. @subsubheading Exceptional Situations::
  445. Should be prepared to signal an error of @i{type} @b{type-error}
  446. if @i{sequence} is not a @i{proper sequence}.
  447. Should be prepared to signal an error of @i{type} @b{type-error}
  448. if @i{new-subsequence} is not a @i{proper sequence}.
  449. @subsubheading See Also::
  450. @ref{replace}
  451. @node map, map-into, subseq, Sequences Dictionary
  452. @subsection map [Function]
  453. @code{map} @i{result-type function {&rest} sequences^+} @result{} @i{result}
  454. @subsubheading Arguments and Values::
  455. @i{result-type} -- a @b{sequence} @i{type specifier}, or @b{nil}.
  456. @i{function}---a @i{function designator}.
  457. @i{function} must take as many arguments as
  458. there are @i{sequences}.
  459. @i{sequence}---a @i{proper sequence}.
  460. @i{result}---if @i{result-type} is a @i{type specifier} other than @b{nil},
  461. then a @i{sequence} of the @i{type} it denotes;
  462. otherwise (if the @i{result-type} is @b{nil}), @b{nil}.
  463. @subsubheading Description::
  464. Applies @i{function} to successive sets of arguments in which
  465. one argument is obtained from each @i{sequence}.
  466. The @i{function} is called first on all the elements with index @t{0},
  467. then on all those with index @t{1}, and so on.
  468. The @i{result-type} specifies the @i{type} of the resulting @i{sequence}.
  469. @b{map} returns @b{nil} if @i{result-type} is @b{nil}.
  470. Otherwise, @b{map} returns
  471. a @i{sequence} such that element @t{j} is the result
  472. of applying @i{function} to element @t{j} of each of the
  473. @i{sequences}. The result @i{sequence}
  474. is as long as the shortest of the
  475. @i{sequences}.
  476. The consequences are undefined if the result of applying @i{function}
  477. to the successive elements of the @i{sequences} cannot
  478. be contained in a @i{sequence} of the @i{type} given by @i{result-type}.
  479. If the @i{result-type} is a @i{subtype} of @b{list},
  480. the result will be a @i{list}.
  481. If the @i{result-type} is a @i{subtype} of @b{vector},
  482. then if the implementation can determine the element type specified
  483. for the @i{result-type}, the element type of the resulting array
  484. is the result of @i{upgrading} that element type; or, if the
  485. implementation can determine that the element type is unspecified (or @t{*}),
  486. the element type of the resulting array is @b{t};
  487. otherwise, an error is signaled.
  488. @subsubheading Examples::
  489. @example
  490. (map 'string #'(lambda (x y)
  491. (char "01234567890ABCDEF" (mod (+ x y) 16)))
  492. '(1 2 3 4)
  493. '(10 9 8 7)) @result{} "AAAA"
  494. (setq seq '("lower" "UPPER" "" "123")) @result{} ("lower" "UPPER" "" "123")
  495. (map nil #'nstring-upcase seq) @result{} NIL
  496. seq @result{} ("LOWER" "UPPER" "" "123")
  497. (map 'list #'- '(1 2 3 4)) @result{} (-1 -2 -3 -4)
  498. (map 'string
  499. #'(lambda (x) (if (oddp x) #\1 #\0))
  500. '(1 2 3 4)) @result{} "1010"
  501. @end example
  502. @example
  503. (map '(vector * 4) #'cons "abc" "de") should signal an error
  504. @end example
  505. @subsubheading Exceptional Situations::
  506. An error of @i{type} @b{type-error} must be signaled if the @i{result-type} is
  507. not a @i{recognizable subtype} of @b{list},
  508. not a @i{recognizable subtype} of @b{vector},
  509. and not @b{nil}.
  510. Should be prepared to signal an error of @i{type} @b{type-error}
  511. if any @i{sequence} is not a @i{proper sequence}.
  512. An error of @i{type} @b{type-error} should be signaled
  513. if @i{result-type} specifies the
  514. number of elements and the minimum length of the @i{sequences}
  515. is different from that number.
  516. @subsubheading See Also::
  517. @ref{Traversal Rules and Side Effects}
  518. @node map-into, reduce, map, Sequences Dictionary
  519. @subsection map-into [Function]
  520. @code{map-into} @i{result-sequence function {&rest} sequences} @result{} @i{result-sequence}
  521. @subsubheading Arguments and Values::
  522. @i{result-sequence}---a @i{proper sequence}.
  523. @i{function}---a @i{designator} for a @i{function}
  524. of as many @i{arguments} as there are @i{sequences}.
  525. @i{sequence}---a @i{proper sequence}.
  526. @subsubheading Description::
  527. Destructively modifies @i{result-sequence} to contain the results of
  528. applying @i{function} to each element in the argument @i{sequences}
  529. in turn.
  530. @i{result-sequence} and each element of @i{sequences} can each be
  531. either a @i{list} or a @i{vector}.
  532. If @i{result-sequence} and each element of @i{sequences} are not all
  533. the same length, the iteration terminates when the shortest @i{sequence}
  534. (of any of the @i{sequences} or the @i{result-sequence})
  535. is exhausted.
  536. If @i{result-sequence} is a @i{vector} with a
  537. @i{fill pointer}, the @i{fill pointer} is ignored when deciding how
  538. many iterations to perform, and afterwards the @i{fill pointer} is set to
  539. the number of times @i{function} was applied.
  540. If @i{result-sequence} is longer than the shortest element of @i{sequences},
  541. extra elements at the end of @i{result-sequence} are left unchanged.
  542. If @i{result-sequence} is @b{nil}, @b{map-into} immediately returns
  543. @b{nil}, since @b{nil} is a @i{sequence} of length zero.
  544. If @i{function} has side effects, it can count on being called
  545. first on all of the elements with index 0, then on all of those
  546. numbered 1, and so on.
  547. @subsubheading Examples::
  548. @example
  549. (setq a (list 1 2 3 4) b (list 10 10 10 10)) @result{} (10 10 10 10)
  550. (map-into a #'+ a b) @result{} (11 12 13 14)
  551. a @result{} (11 12 13 14)
  552. b @result{} (10 10 10 10)
  553. (setq k '(one two three)) @result{} (ONE TWO THREE)
  554. (map-into a #'cons k a) @result{} ((ONE . 11) (TWO . 12) (THREE . 13) 14)
  555. (map-into a #'gensym) @result{} (#:G9090 #:G9091 #:G9092 #:G9093)
  556. a @result{} (#:G9090 #:G9091 #:G9092 #:G9093)
  557. @end example
  558. @subsubheading Exceptional Situations::
  559. Should be prepared to signal an error of @i{type} @b{type-error}
  560. if @i{result-sequence} is not a @i{proper sequence}.
  561. Should be prepared to signal an error of @i{type} @b{type-error}
  562. if @i{sequence} is not a @i{proper sequence}.
  563. @subsubheading Notes::
  564. @b{map-into} differs from @b{map} in that it modifies an
  565. existing @i{sequence} rather than creating a new one.
  566. In addition, @b{map-into} can be called with only two
  567. arguments, while @b{map} requires at least three arguments.
  568. @b{map-into} could be defined by:
  569. @example
  570. (defun map-into (result-sequence function &rest sequences)
  571. (loop for index below (apply #'min
  572. (length result-sequence)
  573. (mapcar #'length sequences))
  574. do (setf (elt result-sequence index)
  575. (apply function
  576. (mapcar #'(lambda (seq) (elt seq index))
  577. sequences))))
  578. result-sequence)
  579. @end example
  580. @node reduce, count, map-into, Sequences Dictionary
  581. @subsection reduce [Function]
  582. @code{reduce} @i{function sequence {&key} key from-end start end initial-value} @result{} @i{result}
  583. @subsubheading Arguments and Values::
  584. @i{function}---a @i{designator} for a @i{function}
  585. that might be called with either zero or two @i{arguments}.
  586. @i{sequence}---a @i{proper sequence}.
  587. @i{key}---a @i{designator} for a @i{function} of one argument,
  588. or @b{nil}.
  589. @i{from-end}---a @i{generalized boolean}.
  590. The default is @i{false}.
  591. @i{start}, @i{end}---@i{bounding index designators} of @i{sequence}.
  592. The defaults for @i{start} and @i{end} are @t{0} and @b{nil}, respectively.
  593. @i{initial-value}---an @i{object}.
  594. @i{result}---an @i{object}.
  595. @subsubheading Description::
  596. @b{reduce} uses a binary operation, @i{function},
  597. to combine the @i{elements} of @i{sequence}
  598. @i{bounded} by @i{start} and @i{end}.
  599. The @i{function} must accept as @i{arguments} two @i{elements}
  600. of @i{sequence} or the results from combining those @i{elements}.
  601. The @i{function} must also be able to accept no arguments.
  602. If @i{key} is supplied, it is used is used to extract the values to reduce.
  603. The @i{key} function is applied exactly once to each element of @i{sequence}
  604. in the order implied by the reduction order but not to the value of
  605. @i{initial-value}, if supplied.
  606. The @i{key} function typically returns part of the @i{element} of @i{sequence}.
  607. If @i{key} is not supplied or is @b{nil}, the @i{sequence} @i{element} itself is used.
  608. The reduction is left-associative,
  609. unless @i{from-end} is @i{true} in which case it is right-associative.
  610. If @i{initial-value} is supplied,
  611. it is logically placed before the subsequence
  612. (or after it if @i{from-end} is @i{true})
  613. and included in the reduction operation.
  614. In the normal case, the result of @b{reduce} is the combined
  615. result of @i{function}'s being applied to successive pairs of @i{elements}
  616. of @i{sequence}.
  617. If the subsequence contains exactly one @i{element}
  618. and no @i{initial-value} is given,
  619. then that @i{element} is returned and @i{function} is not called.
  620. If the subsequence is empty and an @i{initial-value} is given,
  621. then the @i{initial-value} is returned and @i{function} is not called.
  622. If the subsequence is empty and no @i{initial-value} is given,
  623. then the @i{function} is called with zero arguments,
  624. and @b{reduce} returns whatever @i{function} does.
  625. This is the only case where the
  626. @i{function} is called with other than two arguments.
  627. @subsubheading Examples::
  628. @example
  629. (reduce #'* '(1 2 3 4 5)) @result{} 120
  630. (reduce #'append '((1) (2)) :initial-value '(i n i t)) @result{} (I N I T 1 2)
  631. (reduce #'append '((1) (2)) :from-end t
  632. :initial-value '(i n i t)) @result{} (1 2 I N I T)
  633. (reduce #'- '(1 2 3 4)) @equiv{} (- (- (- 1 2) 3) 4) @result{} -8
  634. (reduce #'- '(1 2 3 4) :from-end t) ;Alternating sum.
  635. @equiv{} (- 1 (- 2 (- 3 4))) @result{} -2
  636. (reduce #'+ '()) @result{} 0
  637. (reduce #'+ '(3)) @result{} 3
  638. (reduce #'+ '(foo)) @result{} FOO
  639. (reduce #'list '(1 2 3 4)) @result{} (((1 2) 3) 4)
  640. (reduce #'list '(1 2 3 4) :from-end t) @result{} (1 (2 (3 4)))
  641. (reduce #'list '(1 2 3 4) :initial-value 'foo) @result{} ((((foo 1) 2) 3) 4)
  642. (reduce #'list '(1 2 3 4)
  643. :from-end t :initial-value 'foo) @result{} (1 (2 (3 (4 foo))))
  644. @end example
  645. @subsubheading Exceptional Situations::
  646. Should be prepared to signal an error of @i{type} @b{type-error}
  647. if @i{sequence} is not a @i{proper sequence}.
  648. @subsubheading See Also::
  649. @ref{Traversal Rules and Side Effects}
  650. @node count, length, reduce, Sequences Dictionary
  651. @subsection count, count-if, count-if-not [Function]
  652. @code{count} @i{item sequence {&key} from-end start end key test test-not} @result{} @i{n}
  653. @code{count-if} @i{predicate sequence {&key} from-end start end key} @result{} @i{n}
  654. @code{count-if-not} @i{predicate sequence {&key} from-end start end key} @result{} @i{n}
  655. @subsubheading Arguments and Values::
  656. @i{item}---an @i{object}.
  657. @i{sequence}---a @i{proper sequence}.
  658. @i{predicate}---a @i{designator} for a @i{function} of one @i{argument}
  659. that returns a @i{generalized boolean}.
  660. @i{from-end}---a @i{generalized boolean}.
  661. The default is @i{false}.
  662. @i{test}---a @i{designator} for a @i{function} of two @i{arguments}
  663. that returns a @i{generalized boolean}.
  664. @i{test-not}---a @i{designator} for
  665. a @i{function} of two @i{arguments}
  666. that returns a @i{generalized boolean}.
  667. @i{start}, @i{end}---@i{bounding index designators} of @i{sequence}.
  668. The defaults for @i{start} and @i{end} are @t{0} and @b{nil}, respectively.
  669. @i{key}---a @i{designator} for a @i{function} of one argument,
  670. or @b{nil}.
  671. @i{n}---a non-negative @i{integer}
  672. less than or equal to the @i{length} of @i{sequence}.
  673. @subsubheading Description::
  674. @b{count}, @b{count-if}, and @b{count-if-not}
  675. count and return the number of @i{elements} in
  676. the @i{sequence} @i{bounded} by @i{start} and @i{end}
  677. that @i{satisfy the test}.
  678. The @i{from-end} has no direct effect on the result.
  679. However, if @i{from-end} is @i{true},
  680. the @i{elements} of @i{sequence} will be supplied as @i{arguments} to
  681. the @i{test},
  682. @i{test-not},
  683. and @i{key} in reverse order,
  684. which may change the side-effects, if any, of those functions.
  685. @subsubheading Examples::
  686. @example
  687. (count #\a "how many A's are there in here?") @result{} 2
  688. (count-if-not #'oddp '((1) (2) (3) (4)) :key #'car) @result{} 2
  689. (count-if #'upper-case-p "The Crying of Lot 49" :start 4) @result{} 2
  690. @end example
  691. @subsubheading Exceptional Situations::
  692. Should be prepared to signal an error of @i{type} @b{type-error}
  693. if @i{sequence} is not a @i{proper sequence}.
  694. @subsubheading See Also::
  695. @ref{Rules about Test Functions},
  696. @ref{Traversal Rules and Side Effects}
  697. @subsubheading Notes::
  698. The @t{:test-not} @i{argument} is deprecated.
  699. The @i{function} @b{count-if-not} is deprecated.
  700. @node length, reverse, count, Sequences Dictionary
  701. @subsection length [Function]
  702. @code{length} @i{sequence} @result{} @i{n}
  703. @subsubheading Arguments and Values::
  704. @i{sequence}---a @i{proper sequence}.
  705. @i{n}---a non-negative @i{integer}.
  706. @subsubheading Description::
  707. Returns the number of @i{elements} in @i{sequence}.
  708. If @i{sequence} is a @i{vector} with a @i{fill pointer},
  709. the active length as specified by the @i{fill pointer} is returned.
  710. @subsubheading Examples::
  711. @example
  712. (length "abc") @result{} 3
  713. (setq str (make-array '(3) :element-type 'character
  714. :initial-contents "abc"
  715. :fill-pointer t)) @result{} "abc"
  716. (length str) @result{} 3
  717. (setf (fill-pointer str) 2) @result{} 2
  718. (length str) @result{} 2
  719. @end example
  720. @subsubheading Exceptional Situations::
  721. Should be prepared to signal an error of @i{type} @b{type-error}
  722. if @i{sequence} is not a @i{proper sequence}.
  723. @subsubheading See Also::
  724. @ref{list-length}
  725. ,
  726. @b{sequence}
  727. @node reverse, sort, length, Sequences Dictionary
  728. @subsection reverse, nreverse [Function]
  729. @code{reverse} @i{sequence} @result{} @i{reversed-sequence}
  730. @code{nreverse} @i{sequence} @result{} @i{reversed-sequence}
  731. @subsubheading Arguments and Values::
  732. @i{sequence}---a @i{proper sequence}.
  733. @i{reversed-sequence}---a @i{sequence}.
  734. @subsubheading Description::
  735. @b{reverse} and @b{nreverse} return a new @i{sequence}
  736. of the same kind as @i{sequence}, containing the same @i{elements},
  737. but in reverse order.
  738. @b{reverse} and @b{nreverse} differ in that @b{reverse}
  739. always creates and returns a new @i{sequence}, whereas @b{nreverse}
  740. might modify and return the given @i{sequence}. @b{reverse} never
  741. modifies the given @i{sequence}.
  742. For @b{reverse}, if @i{sequence} is a @i{vector},
  743. the result is a @i{fresh} @i{simple array} of @i{rank} one
  744. that has the same @i{actual array element type} as @i{sequence}.
  745. If @i{sequence} is a @i{list}, the result is a @i{fresh} @i{list}.
  746. For @b{nreverse}, if @i{sequence} is a @i{vector},
  747. the result is a @i{vector}
  748. that has the same @i{actual array element type} as @i{sequence}.
  749. If @i{sequence} is a @i{list}, the result is a @i{list}.
  750. For @b{nreverse},
  751. @i{sequence} might be destroyed and re-used to produce the result.
  752. The result might or might not be @i{identical} to @i{sequence}.
  753. Specifically, when @i{sequence} is a @i{list},
  754. @b{nreverse} is permitted to @b{setf} any part, @b{car} or @b{cdr},
  755. of any @i{cons} that is part of the @i{list structure} of @i{sequence}.
  756. When @i{sequence} is a @i{vector},
  757. @b{nreverse} is permitted to re-order the elements of @i{sequence}
  758. in order to produce the resulting @i{vector}.
  759. @subsubheading Examples::
  760. @example
  761. (setq str "abc") @result{} "abc"
  762. (reverse str) @result{} "cba"
  763. str @result{} "abc"
  764. (setq str (copy-seq str)) @result{} "abc"
  765. (nreverse str) @result{} "cba"
  766. str @result{} @i{implementation-dependent}
  767. (setq l (list 1 2 3)) @result{} (1 2 3)
  768. (nreverse l) @result{} (3 2 1)
  769. l @result{} @i{implementation-dependent}
  770. @end example
  771. @subsubheading Side Effects::
  772. @b{nreverse} might either create a new @i{sequence},
  773. modify the argument @i{sequence}, or both.
  774. (@b{reverse} does not modify @i{sequence}.)
  775. @subsubheading Exceptional Situations::
  776. Should be prepared to signal an error of @i{type} @b{type-error}
  777. if @i{sequence} is not a @i{proper sequence}.
  778. @node sort, find, reverse, Sequences Dictionary
  779. @subsection sort, stable-sort [Function]
  780. @code{sort} @i{sequence predicate {&key} key} @result{} @i{sorted-sequence}
  781. @code{stable-sort} @i{sequence predicate {&key} key} @result{} @i{sorted-sequence}
  782. @subsubheading Arguments and Values::
  783. @i{sequence}---a @i{proper sequence}.
  784. @i{predicate}---a @i{designator} for
  785. a @i{function} of two arguments that returns a @i{generalized boolean}.
  786. @i{key}---a @i{designator} for a @i{function} of one argument,
  787. or @b{nil}.
  788. @i{sorted-sequence}---a @i{sequence}.
  789. @subsubheading Description::
  790. @b{sort} and @b{stable-sort} destructively sort @i{sequences}
  791. according to the order determined by the @i{predicate} function.
  792. If @i{sequence} is a @i{vector},
  793. the result is a @i{vector}
  794. that has the same @i{actual array element type} as @i{sequence}.
  795. The result might or might not be simple,
  796. and might or might not be @i{identical} to @i{sequence}.
  797. If @i{sequence} is a @i{list},
  798. the result is a @i{list}.
  799. @b{sort} determines the relationship between two elements
  800. by giving keys extracted from the elements to the @i{predicate}.
  801. The first argument to the @i{predicate} function is the part of one element
  802. of @i{sequence} extracted by the @i{key} function
  803. (if supplied); the second
  804. argument is the part of another element
  805. of @i{sequence} extracted by the @i{key} function
  806. (if supplied).
  807. @i{Predicate} should return @i{true} if and only if the first argument is
  808. strictly less than the second (in some appropriate sense).
  809. If the first argument is greater than or equal to the second
  810. (in the appropriate sense), then the @i{predicate} should return @i{false}.
  811. The argument to the @i{key} function is the @i{sequence} element.
  812. The return value of the @i{key} function
  813. becomes an argument to @i{predicate}.
  814. If @i{key} is not supplied or @b{nil}, the @i{sequence} element itself is used.
  815. There is no guarantee on the number of times the @i{key} will be called.
  816. If the @i{key} and @i{predicate} always return,
  817. then the sorting operation will always terminate,
  818. producing a @i{sequence} containing the same @i{elements} as @i{sequence}
  819. (that is, the result is a permutation of @i{sequence}).
  820. This is guaranteed even if the @i{predicate}
  821. does not really consistently represent a total order
  822. (in which case the @i{elements} will be scrambled in some unpredictable way,
  823. but no @i{element} will be lost).
  824. If the @i{key} consistently returns meaningful keys,
  825. and the @i{predicate} does reflect some total ordering criterion on those keys,
  826. then the @i{elements} of the @i{sorted-sequence}
  827. will be properly sorted according to that ordering.
  828. The sorting operation performed by @b{sort} is not guaranteed stable.
  829. Elements considered equal by the @i{predicate} might or might not
  830. stay in their original order. The @i{predicate} is assumed to
  831. consider two elements @t{x} and @t{y} to be equal if
  832. @t{(funcall @i{predicate} @i{x} @i{y})} and
  833. @t{(funcall @i{predicate} @i{y} @i{x})} are both @i{false}.
  834. @b{stable-sort} guarantees stability.
  835. The sorting operation can be destructive in all cases. In the case of a
  836. @i{vector}
  837. argument, this is accomplished by permuting the elements in place.
  838. In the case of a @i{list}, the @i{list} is
  839. destructively reordered in the same manner as for
  840. @b{nreverse}.
  841. @subsubheading Examples::
  842. @example
  843. (setq tester (copy-seq "lkjashd")) @result{} "lkjashd"
  844. (sort tester #'char-lessp) @result{} "adhjkls"
  845. (setq tester (list '(1 2 3) '(4 5 6) '(7 8 9))) @result{} ((1 2 3) (4 5 6) (7 8 9))
  846. (sort tester #'> :key #'car) @result{} ((7 8 9) (4 5 6) (1 2 3))
  847. (setq tester (list 1 2 3 4 5 6 7 8 9 0)) @result{} (1 2 3 4 5 6 7 8 9 0)
  848. (stable-sort tester #'(lambda (x y) (and (oddp x) (evenp y))))
  849. @result{} (1 3 5 7 9 2 4 6 8 0)
  850. (sort (setq committee-data
  851. (vector (list (list "JonL" "White") "Iteration")
  852. (list (list "Dick" "Waters") "Iteration")
  853. (list (list "Dick" "Gabriel") "Objects")
  854. (list (list "Kent" "Pitman") "Conditions")
  855. (list (list "Gregor" "Kiczales") "Objects")
  856. (list (list "David" "Moon") "Objects")
  857. (list (list "Kathy" "Chapman") "Editorial")
  858. (list (list "Larry" "Masinter") "Cleanup")
  859. (list (list "Sandra" "Loosemore") "Compiler")))
  860. #'string-lessp :key #'cadar)
  861. @result{} #((("Kathy" "Chapman") "Editorial")
  862. (("Dick" "Gabriel") "Objects")
  863. (("Gregor" "Kiczales") "Objects")
  864. (("Sandra" "Loosemore") "Compiler")
  865. (("Larry" "Masinter") "Cleanup")
  866. (("David" "Moon") "Objects")
  867. (("Kent" "Pitman") "Conditions")
  868. (("Dick" "Waters") "Iteration")
  869. (("JonL" "White") "Iteration"))
  870. ;; Note that individual alphabetical order within `committees'
  871. ;; is preserved.
  872. (setq committee-data
  873. (stable-sort committee-data #'string-lessp :key #'cadr))
  874. @result{} #((("Larry" "Masinter") "Cleanup")
  875. (("Sandra" "Loosemore") "Compiler")
  876. (("Kent" "Pitman") "Conditions")
  877. (("Kathy" "Chapman") "Editorial")
  878. (("Dick" "Waters") "Iteration")
  879. (("JonL" "White") "Iteration")
  880. (("Dick" "Gabriel") "Objects")
  881. (("Gregor" "Kiczales") "Objects")
  882. (("David" "Moon") "Objects"))
  883. @end example
  884. @subsubheading Exceptional Situations::
  885. Should be prepared to signal an error of @i{type} @b{type-error}
  886. if @i{sequence} is not a @i{proper sequence}.
  887. @subsubheading See Also::
  888. @ref{merge}
  889. ,
  890. @ref{Compiler Terminology},
  891. @ref{Traversal Rules and Side Effects},
  892. @ref{Destructive Operations}
  893. @node find, position, sort, Sequences Dictionary
  894. @subsection find, find-if, find-if-not [Function]
  895. @code{find} @i{item sequence {&key} from-end test test-not start end key} @result{} @i{element}
  896. @code{find-if} @i{predicate sequence {&key} from-end start end key} @result{} @i{element}
  897. @code{find-if-not} @i{predicate sequence {&key} from-end start end key} @result{} @i{element}
  898. @subsubheading Arguments and Values::
  899. @i{item}---an @i{object}.
  900. @i{sequence}---a @i{proper sequence}.
  901. @i{predicate}---a @i{designator} for a @i{function} of one @i{argument}
  902. that returns a @i{generalized boolean}.
  903. @i{from-end}---a @i{generalized boolean}.
  904. The default is @i{false}.
  905. @i{test}---a @i{designator} for a @i{function} of two @i{arguments}
  906. that returns a @i{generalized boolean}.
  907. @i{test-not}---a @i{designator} for
  908. a @i{function} of two @i{arguments}
  909. that returns a @i{generalized boolean}.
  910. @i{start}, @i{end}---@i{bounding index designators} of @i{sequence}.
  911. The defaults for @i{start} and @i{end} are @t{0} and @b{nil}, respectively.
  912. @i{key}---a @i{designator} for a @i{function} of one argument,
  913. or @b{nil}.
  914. @i{element}---an @i{element} of the @i{sequence}, or @b{nil}.
  915. @subsubheading Description::
  916. @b{find}, @b{find-if}, and @b{find-if-not}
  917. each search for an @i{element} of the @i{sequence}
  918. @i{bounded} by @i{start} and @i{end}
  919. that @i{satisfies the predicate} @i{predicate}
  920. or that @i{satisfies the test} @i{test} or @i{test-not},
  921. as appropriate.
  922. If @i{from-end} is @i{true},
  923. then the result is the rightmost @i{element} that @i{satisfies the test}.
  924. If the @i{sequence} contains an @i{element} that @i{satisfies the test},
  925. then the leftmost or rightmost @i{sequence} element,
  926. depending on @i{from-end},
  927. is returned;
  928. otherwise @b{nil} is returned.
  929. @subsubheading Examples::
  930. @example
  931. (find #\d "here are some letters that can be looked at" :test #'char>)
  932. @result{} #\Space
  933. (find-if #'oddp '(1 2 3 4 5) :end 3 :from-end t) @result{} 3
  934. (find-if-not #'complexp
  935. '#(3.5 2 #C(1.0 0.0) #C(0.0 1.0))
  936. :start 2) @result{} NIL
  937. @end example
  938. @subsubheading Exceptional Situations::
  939. Should be prepared to signal an error of @i{type} @b{type-error}
  940. if @i{sequence} is not a @i{proper sequence}.
  941. @subsubheading See Also::
  942. @ref{position; position-if; position-if-not}
  943. ,
  944. @ref{Rules about Test Functions},
  945. @ref{Traversal Rules and Side Effects}
  946. @subsubheading Notes::
  947. The @t{:test-not} @i{argument} is deprecated.
  948. The @i{function} @b{find-if-not} is deprecated.
  949. @node position, search, find, Sequences Dictionary
  950. @subsection position, position-if, position-if-not [Function]
  951. @code{position} @i{item sequence {&key} from-end test test-not start end key} @result{} @i{position}
  952. @code{position-if} @i{predicate sequence {&key} from-end start end key} @result{} @i{position}
  953. @code{position-if-not} @i{predicate sequence {&key} from-end start end key} @result{} @i{position}
  954. @subsubheading Arguments and Values::
  955. @i{item}---an @i{object}.
  956. @i{sequence}---a @i{proper sequence}.
  957. @i{predicate}---a @i{designator} for a @i{function} of one argument
  958. that returns a @i{generalized boolean}.
  959. @i{from-end}---a @i{generalized boolean}.
  960. The default is @i{false}.
  961. @i{test}---a @i{designator} for a @i{function} of two @i{arguments}
  962. that returns a @i{generalized boolean}.
  963. @i{test-not}---a @i{designator} for
  964. a @i{function} of two @i{arguments}
  965. that returns a @i{generalized boolean}.
  966. @i{start}, @i{end}---@i{bounding index designators} of @i{sequence}.
  967. The defaults for @i{start} and @i{end} are @t{0} and @b{nil}, respectively.
  968. @i{key}---a @i{designator} for a @i{function} of one argument,
  969. or @b{nil}.
  970. @i{position}---a @i{bounding index} of @i{sequence}, or @b{nil}.
  971. @subsubheading Description::
  972. @b{position}, @b{position-if}, and @b{position-if-not}
  973. each search @i{sequence} for an @i{element} that @i{satisfies the test}.
  974. The @i{position} returned is the index within @i{sequence}
  975. of the leftmost (if @i{from-end} is @i{true})
  976. or of the rightmost (if @i{from-end} is @i{false})
  977. @i{element} that @i{satisfies the test};
  978. otherwise @b{nil} is returned.
  979. The index returned is relative to the left-hand end of the entire @i{sequence},
  980. regardless of the value of @i{start}, @i{end}, or @i{from-end}.
  981. @subsubheading Examples::
  982. @example
  983. (position #\a "baobab" :from-end t) @result{} 4
  984. (position-if #'oddp '((1) (2) (3) (4)) :start 1 :key #'car) @result{} 2
  985. (position 595 '()) @result{} NIL
  986. (position-if-not #'integerp '(1 2 3 4 5.0)) @result{} 4
  987. @end example
  988. @subsubheading Exceptional Situations::
  989. Should be prepared to signal an error of @i{type} @b{type-error}
  990. if @i{sequence} is not a @i{proper sequence}.
  991. @subsubheading See Also::
  992. @ref{find; find-if; find-if-not}
  993. ,
  994. @ref{Traversal Rules and Side Effects}
  995. @subsubheading Notes::
  996. The @t{:test-not} @i{argument} is deprecated.
  997. The @i{function} @b{position-if-not} is deprecated.
  998. @node search, mismatch, position, Sequences Dictionary
  999. @subsection search [Function]
  1000. @code{search} @i{sequence-1 sequence-2
  1001. {&key} from-end test test-not
  1002. key start1 start2
  1003. end1 end2}@*
  1004. @result{} @i{position}
  1005. @subsubheading Arguments and Values::
  1006. @i{Sequence-1}---a @i{sequence}.
  1007. @i{Sequence-2}---a @i{sequence}.
  1008. @i{from-end}---a @i{generalized boolean}.
  1009. The default is @i{false}.
  1010. @i{test}---a @i{designator} for a @i{function} of two @i{arguments}
  1011. that returns a @i{generalized boolean}.
  1012. @i{test-not}---a @i{designator} for
  1013. a @i{function} of two @i{arguments}
  1014. that returns a @i{generalized boolean}.
  1015. @i{key}---a @i{designator} for a @i{function} of one argument,
  1016. or @b{nil}.
  1017. @i{start1}, @i{end1}---@i{bounding index designators} of @i{sequence-1}.
  1018. The defaults for @i{start1} and @i{end1} are @t{0} and @b{nil}, respectively.
  1019. @i{start2}, @i{end2}---@i{bounding index designators} of @i{sequence-2}.
  1020. The defaults for @i{start2} and @i{end2} are @t{0} and @b{nil}, respectively.
  1021. @i{position}---a @i{bounding index} of @i{sequence-2},
  1022. or @b{nil}.
  1023. @subsubheading Description::
  1024. Searches @i{sequence-2} for a subsequence that matches @i{sequence-1}.
  1025. The implementation may choose to search @i{sequence-2} in any order;
  1026. there is no guarantee on the number of times the test is made.
  1027. For example,
  1028. when @i{start-end} is @i{true},
  1029. the @i{sequence} might actually be searched from left to right
  1030. instead of from right to left (but in either case would return
  1031. the rightmost matching subsequence).
  1032. If the search succeeds,
  1033. @b{search} returns the offset into @i{sequence-2}
  1034. of the first element of the leftmost or rightmost matching subsequence,
  1035. depending on @i{from-end};
  1036. otherwise @b{search} returns @b{nil}.
  1037. If @i{from-end} is @i{true}, the index of the leftmost
  1038. element of the rightmost matching subsequence is returned.
  1039. @subsubheading Examples::
  1040. @example
  1041. (search "dog" "it's a dog's life") @result{} 7
  1042. (search '(0 1) '(2 4 6 1 3 5) :key #'oddp) @result{} 2
  1043. @end example
  1044. @subsubheading See Also::
  1045. @ref{Traversal Rules and Side Effects}
  1046. @subsubheading Notes::
  1047. The @t{:test-not} @i{argument} is deprecated.
  1048. @node mismatch, replace, search, Sequences Dictionary
  1049. @subsection mismatch [Function]
  1050. @code{mismatch} @i{sequence-1 sequence-2
  1051. {&key} from-end test test-not key start1 start2 end1 end2}@*
  1052. @result{} @i{position}
  1053. @subsubheading Arguments and Values::
  1054. @i{Sequence-1}---a @i{sequence}.
  1055. @i{Sequence-2}---a @i{sequence}.
  1056. @i{from-end}---a @i{generalized boolean}.
  1057. The default is @i{false}.
  1058. @i{test}---a @i{designator} for a @i{function} of two @i{arguments}
  1059. that returns a @i{generalized boolean}.
  1060. @i{test-not}---a @i{designator} for
  1061. a @i{function} of two @i{arguments}
  1062. that returns a @i{generalized boolean}.
  1063. @i{start1}, @i{end1}---@i{bounding index designators} of @i{sequence-1}.
  1064. The defaults for @i{start1} and @i{end1} are @t{0} and @b{nil}, respectively.
  1065. @i{start2}, @i{end2}---@i{bounding index designators} of @i{sequence-2}.
  1066. The defaults for @i{start2} and @i{end2} are @t{0} and @b{nil}, respectively.
  1067. @i{key}---a @i{designator} for a @i{function} of one argument,
  1068. or @b{nil}.
  1069. @i{position}---a @i{bounding index} of @i{sequence-1},
  1070. or @b{nil}.
  1071. @subsubheading Description::
  1072. The specified subsequences of
  1073. @i{sequence-1} and @i{sequence-2} are compared element-wise.
  1074. The @i{key} argument is used for both the @i{sequence-1} and the @i{sequence-2}.
  1075. If @i{sequence-1} and @i{sequence-2}
  1076. are of equal length and match in every element, the result is
  1077. @i{false}. Otherwise, the result is a non-negative @i{integer},
  1078. the index within
  1079. @i{sequence-1} of the leftmost or rightmost position, depending
  1080. on @i{from-end}, at which the two
  1081. subsequences fail to match.
  1082. If one subsequence
  1083. is shorter than and a matching prefix of the other,
  1084. the result is the index
  1085. relative to @i{sequence-1} beyond the last position tested.
  1086. If @i{from-end} is @i{true}, then one plus the index of the rightmost
  1087. position in which the @i{sequences}
  1088. differ is returned. In effect, the subsequences
  1089. are aligned at their right-hand ends; then, the last elements are compared,
  1090. the penultimate elements, and so on. The index returned is
  1091. an index relative to @i{sequence-1}.
  1092. @subsubheading Examples::
  1093. @example
  1094. (mismatch "abcd" "ABCDE" :test #'char-equal) @result{} 4
  1095. (mismatch '(3 2 1 1 2 3) '(1 2 3) :from-end t) @result{} 3
  1096. (mismatch '(1 2 3) '(2 3 4) :test-not #'eq :key #'oddp) @result{} NIL
  1097. (mismatch '(1 2 3 4 5 6) '(3 4 5 6 7) :start1 2 :end2 4) @result{} NIL
  1098. @end example
  1099. @subsubheading See Also::
  1100. @ref{Traversal Rules and Side Effects}
  1101. @subsubheading Notes::
  1102. The @t{:test-not} @i{argument} is deprecated.
  1103. @node replace, substitute, mismatch, Sequences Dictionary
  1104. @subsection replace [Function]
  1105. @code{replace} @i{sequence-1 sequence-2 {&key} start1 end1 start2 end2} @result{} @i{sequence-1}
  1106. @subsubheading Arguments and Values::
  1107. @i{sequence-1}---a @i{sequence}.
  1108. @i{sequence-2}---a @i{sequence}.
  1109. @i{start1}, @i{end1}---@i{bounding index designators} of @i{sequence-1}.
  1110. The defaults for @i{start1} and @i{end1} are @t{0} and @b{nil}, respectively.
  1111. @i{start2}, @i{end2}---@i{bounding index designators} of @i{sequence-2}.
  1112. The defaults for @i{start2} and @i{end2} are @t{0} and @b{nil}, respectively.
  1113. @subsubheading Description::
  1114. Destructively modifies @i{sequence-1}
  1115. by replacing the @i{elements} of @i{subsequence-1}
  1116. @i{bounded} by @i{start1} and @i{end1}
  1117. with the @i{elements} of @i{subsequence-2}
  1118. @i{bounded} by @i{start2} and @i{end2}.
  1119. @i{Sequence-1} is destructively modified by copying successive
  1120. @i{elements} into it from @i{sequence-2}.
  1121. @i{Elements} of the subsequence of @i{sequence-2}
  1122. @i{bounded} by @i{start2} and @i{end2}
  1123. are copied into the subsequence of @i{sequence-1}
  1124. @i{bounded} by @i{start1} and @i{end1}.
  1125. If these subsequences are not of the same length,
  1126. then the shorter length determines how many @i{elements} are copied;
  1127. the extra @i{elements} near the end of the longer subsequence
  1128. are not involved in the operation.
  1129. The number of elements copied can be expressed as:
  1130. @example
  1131. (min (- @i{end1} @i{start1}) (- @i{end2} @i{start2}))
  1132. @end example
  1133. If @i{sequence-1} and @i{sequence-2} are the @i{same} @i{object}
  1134. and the region being modified overlaps the region being copied
  1135. from, then it is as if the entire source region were copied to another
  1136. place and only then copied back into the target region.
  1137. However, if @i{sequence-1} and @i{sequence-2} are not the same,
  1138. but the region being modified overlaps the region being copied from
  1139. (perhaps because of shared list structure or displaced @i{arrays}),
  1140. then after the @b{replace} operation
  1141. the subsequence of @i{sequence-1} being modified will have
  1142. unpredictable contents.
  1143. It is an error if the elements of @i{sequence-2} are not of a
  1144. @i{type} that can be stored into @i{sequence-1}.
  1145. @subsubheading Examples::
  1146. @example
  1147. (replace "abcdefghij" "0123456789" :start1 4 :end1 7 :start2 4)
  1148. @result{} "abcd456hij"
  1149. (setq lst "012345678") @result{} "012345678"
  1150. (replace lst lst :start1 2 :start2 0) @result{} "010123456"
  1151. lst @result{} "010123456"
  1152. @end example
  1153. @subsubheading Side Effects::
  1154. The @i{sequence-1} is modified.
  1155. @subsubheading See Also::
  1156. @ref{fill}
  1157. @node substitute, concatenate, replace, Sequences Dictionary
  1158. @subsection substitute, substitute-if, substitute-if-not,
  1159. @subheading nsubstitute, nsubstitute-if, nsubstitute-if-not
  1160. @flushright
  1161. @i{[Function]}
  1162. @end flushright
  1163. @code{substitute} @i{newitem olditem sequence
  1164. {&key} from-end test
  1165. test-not start
  1166. end count key}@*
  1167. @result{} @i{result-sequence}
  1168. @code{substitute-if} @i{newitem predicate sequence {&key} from-end start end count key}@*
  1169. @result{} @i{result-sequence}
  1170. @code{substitute-if-not} @i{newitem predicate sequence {&key} from-end start end count key}@*
  1171. @result{} @i{result-sequence}
  1172. @code{nsubstitute} @i{newitem olditem sequence
  1173. {&key} from-end test test-not start end count key}@*
  1174. @result{} @i{sequence}
  1175. @code{nsubstitute-if} @i{newitem predicate sequence {&key} from-end start end count key}@*
  1176. @result{} @i{sequence}
  1177. @code{nsubstitute-if-not} @i{newitem predicate sequence {&key} from-end start end count key}@*
  1178. @result{} @i{sequence}
  1179. @subsubheading Arguments and Values::
  1180. @i{newitem}---an @i{object}.
  1181. @i{olditem}---an @i{object}.
  1182. @i{sequence}---a @i{proper sequence}.
  1183. @i{predicate}---a @i{designator} for a @i{function} of one @i{argument}
  1184. that returns a @i{generalized boolean}.
  1185. @i{from-end}---a @i{generalized boolean}.
  1186. The default is @i{false}.
  1187. @i{test}---a @i{designator} for a @i{function} of two @i{arguments}
  1188. that returns a @i{generalized boolean}.
  1189. @i{test-not}---a @i{designator} for
  1190. a @i{function} of two @i{arguments}
  1191. that returns a @i{generalized boolean}.
  1192. @i{start}, @i{end}---@i{bounding index designators} of @i{sequence}.
  1193. The defaults for @i{start} and @i{end} are @t{0} and @b{nil}, respectively.
  1194. @i{count}---an @i{integer} or @b{nil}.
  1195. The default is @b{nil}.
  1196. @i{key}---a @i{designator} for a @i{function} of one argument,
  1197. or @b{nil}.
  1198. @i{result-sequence}---a @i{sequence}.
  1199. @subsubheading Description::
  1200. @b{substitute}, @b{substitute-if}, and @b{substitute-if-not}
  1201. return a
  1202. copy of @i{sequence} in which each @i{element}
  1203. that @i{satisfies the test} has been replaced with @i{newitem}.
  1204. @b{nsubstitute}, @b{nsubstitute-if}, and @b{nsubstitute-if-not}
  1205. are like @b{substitute}, @b{substitute-if}, and
  1206. @b{substitute-if-not} respectively, but they may modify
  1207. @i{sequence}.
  1208. If
  1209. @i{sequence} is a @i{vector}, the result is a
  1210. @i{vector} that has the same
  1211. @i{actual array element type} as @i{sequence}.
  1212. The result might or might not be simple, and
  1213. might or might not be @i{identical}
  1214. to @i{sequence}.
  1215. If @i{sequence} is a @i{list}, the result is a
  1216. @i{list}.
  1217. @i{Count}, if supplied, limits the number of elements
  1218. altered; if more than @i{count} @i{elements} @i{satisfy the test},
  1219. then of these @i{elements} only the leftmost or rightmost, depending
  1220. on @i{from-end}, are replaced,
  1221. as many as specified by @i{count}.
  1222. If @i{count} is supplied and negative,
  1223. the behavior is as if zero had been supplied instead.
  1224. If @i{count} is @b{nil}, all matching items are affected.
  1225. Supplying a @i{from-end} of @i{true} matters only when the
  1226. @i{count} is provided (and @i{non-nil});
  1227. in that case,
  1228. only the rightmost @i{count} @i{elements} @i{satisfying the test} are removed
  1229. (instead of the leftmost).
  1230. @i{predicate}, @i{test}, and @i{test-not}
  1231. might be called more than once for each @i{sequence} @i{element},
  1232. and their side effects can happen in any order.
  1233. The result of all these functions is a @i{sequence}
  1234. of the same @i{type} as @i{sequence}
  1235. that has the same elements except that those in the subsequence
  1236. @i{bounded} by @i{start} and @i{end} and @i{satisfying the test}
  1237. have been replaced by @i{newitem}.
  1238. @b{substitute}, @b{substitute-if}, and @b{substitute-if-not}
  1239. return a @i{sequence} which can share with @i{sequence}
  1240. or may be @i{identical} to the input @i{sequence}
  1241. if no elements need to be changed.
  1242. @b{nsubstitute} and @b{nsubstitute-if} are required to
  1243. @b{setf} any @b{car} (if @i{sequence} is a @i{list})
  1244. or @b{aref} (if @i{sequence} is a @i{vector})
  1245. of @i{sequence} that is required to be replaced with @i{newitem}.
  1246. If @i{sequence} is a @i{list},
  1247. none of the @i{cdrs} of the top-level @i{list} can be modified.
  1248. @subsubheading Examples::
  1249. @example
  1250. (substitute #\. #\SPACE "0 2 4 6") @result{} "0.2.4.6"
  1251. (substitute 9 4 '(1 2 4 1 3 4 5)) @result{} (1 2 9 1 3 9 5)
  1252. (substitute 9 4 '(1 2 4 1 3 4 5) :count 1) @result{} (1 2 9 1 3 4 5)
  1253. (substitute 9 4 '(1 2 4 1 3 4 5) :count 1 :from-end t)
  1254. @result{} (1 2 4 1 3 9 5)
  1255. (substitute 9 3 '(1 2 4 1 3 4 5) :test #'>) @result{} (9 9 4 9 3 4 5)
  1256. (substitute-if 0 #'evenp '((1) (2) (3) (4)) :start 2 :key #'car)
  1257. @result{} ((1) (2) (3) 0)
  1258. (substitute-if 9 #'oddp '(1 2 4 1 3 4 5)) @result{} (9 2 4 9 9 4 9)
  1259. (substitute-if 9 #'evenp '(1 2 4 1 3 4 5) :count 1 :from-end t)
  1260. @result{} (1 2 4 1 3 9 5)
  1261. (setq some-things (list 'a 'car 'b 'cdr 'c)) @result{} (A CAR B CDR C)
  1262. (nsubstitute-if "function was here" #'fboundp some-things
  1263. :count 1 :from-end t) @result{} (A CAR B "function was here" C)
  1264. some-things @result{} (A CAR B "function was here" C)
  1265. (setq alpha-tester (copy-seq "ab ")) @result{} "ab "
  1266. (nsubstitute-if-not #\z #'alpha-char-p alpha-tester) @result{} "abz"
  1267. alpha-tester @result{} "abz"
  1268. @end example
  1269. @subsubheading Side Effects::
  1270. @b{nsubstitute}, @b{nsubstitute-if}, and @b{nsubstitute-if-not}
  1271. modify @i{sequence}.
  1272. @subsubheading Exceptional Situations::
  1273. Should be prepared to signal an error of @i{type} @b{type-error}
  1274. if @i{sequence} is not a @i{proper sequence}.
  1275. @subsubheading See Also::
  1276. @ref{subst; subst-if; subst-if-not; nsubst; nsubst-if; nsubst-if-not}
  1277. ,
  1278. @b{nsubst},
  1279. @ref{Compiler Terminology},
  1280. @ref{Traversal Rules and Side Effects}
  1281. @subsubheading Notes::
  1282. The @t{:test-not} @i{argument} is deprecated.
  1283. The functions @b{substitute-if-not} and @b{nsubstitute-if-not} are deprecated.
  1284. @b{nsubstitute} and @b{nsubstitute-if} can be used
  1285. in for-effect-only positions in code.
  1286. Because the side-effecting variants (@i{e.g.}, @b{nsubstitute})
  1287. potentially change the path that is being traversed, their effects in
  1288. the presence of shared or circular structure may vary in surprising ways when
  1289. compared to their non-side-effecting alternatives. To see this,
  1290. consider the following side-effect behavior, which might be exhibited by
  1291. some implementations:
  1292. @example
  1293. (defun test-it (fn)
  1294. (let ((x (cons 'b nil)))
  1295. (rplacd x x)
  1296. (funcall fn 'a 'b x :count 1)))
  1297. (test-it #'substitute) @result{} (A . #1=(B . #1#))
  1298. (test-it #'nsubstitute) @result{} (A . #1#)
  1299. @end example
  1300. @node concatenate, merge, substitute, Sequences Dictionary
  1301. @subsection concatenate [Function]
  1302. @code{concatenate} @i{result-type {&rest} sequences} @result{} @i{result-sequence}
  1303. @subsubheading Arguments and Values::
  1304. @i{result-type}---a @b{sequence} @i{type specifier}.
  1305. @i{sequences}---a @i{sequence}.
  1306. @i{result-sequence}---a @i{proper sequence} of @i{type} @i{result-type}.
  1307. @subsubheading Description::
  1308. @b{concatenate} returns a @i{sequence} that contains
  1309. all the individual elements of all the @i{sequences} in the order
  1310. that they are supplied.
  1311. The @i{sequence} is of type @i{result-type},
  1312. which must be a @i{subtype} of @i{type} @b{sequence}.
  1313. All of the @i{sequences} are copied from; the result
  1314. does not share any structure with any of the @i{sequences}.
  1315. Therefore, if only one @i{sequence} is provided
  1316. and it is of type @i{result-type},
  1317. @b{concatenate} is required to copy @i{sequence} rather than simply
  1318. returning it.
  1319. It is an error if any element of the @i{sequences} cannot be an
  1320. element of the @i{sequence} result.
  1321. [Reviewer Note by Barmar: Should signal?]
  1322. If the @i{result-type} is a @i{subtype} of @b{list},
  1323. the result will be a @i{list}.
  1324. If the @i{result-type} is a @i{subtype} of @b{vector},
  1325. then if the implementation can determine the element type specified
  1326. for the @i{result-type}, the element type of the resulting array
  1327. is the result of @i{upgrading} that element type; or, if the
  1328. implementation can determine that the element type is unspecified (or @t{*}),
  1329. the element type of the resulting array is @b{t};
  1330. otherwise, an error is signaled.
  1331. @subsubheading Examples::
  1332. @example
  1333. (concatenate 'string "all" " " "together" " " "now") @result{} "all together now"
  1334. (concatenate 'list "ABC" '(d e f) #(1 2 3) #*1011)
  1335. @result{} (#\A #\B #\C D E F 1 2 3 1 0 1 1)
  1336. (concatenate 'list) @result{} NIL
  1337. @end example
  1338. @example
  1339. (concatenate '(vector * 2) "a" "bc") should signal an error
  1340. @end example
  1341. @subsubheading Exceptional Situations::
  1342. An error is signaled if the @i{result-type} is neither
  1343. a @i{recognizable subtype} of @b{list},
  1344. nor a @i{recognizable subtype} of @b{vector}.
  1345. An error of @i{type} @b{type-error} should be signaled if @i{result-type}
  1346. specifies the number of elements and the sum of @i{sequences}
  1347. is different from that number.
  1348. @subsubheading See Also::
  1349. @ref{append}
  1350. @node merge, remove, concatenate, Sequences Dictionary
  1351. @subsection merge [Function]
  1352. @code{merge} @i{result-type sequence-1 sequence-2 predicate {&key} key} @result{} @i{result-sequence}
  1353. @subsubheading Arguments and Values::
  1354. @i{result-type}---a @b{sequence} @i{type specifier}.
  1355. @i{sequence-1}---a @i{sequence}.
  1356. @i{sequence-2}---a @i{sequence}.
  1357. @i{predicate}---a @i{designator} for
  1358. a @i{function} of two arguments that returns a @i{generalized boolean}.
  1359. @i{key}---a @i{designator} for a @i{function} of one argument,
  1360. or @b{nil}.
  1361. @i{result-sequence}---a @i{proper sequence} of @i{type} @i{result-type}.
  1362. @subsubheading Description::
  1363. Destructively merges @i{sequence-1} with @i{sequence-2} according
  1364. to an order determined by the @i{predicate}. @b{merge} determines
  1365. the relationship between two elements by giving keys extracted from the
  1366. sequence elements to the @i{predicate}.
  1367. The first argument to the @i{predicate} function is an element of
  1368. @i{sequence-1} as returned by the @i{key} (if supplied);
  1369. the second argument is an element of @i{sequence-2} as returned by
  1370. the @i{key} (if supplied).
  1371. @i{Predicate} should return @i{true} if and only if its first
  1372. argument is strictly less than the second (in some appropriate sense).
  1373. If the first argument is greater than or equal to the second
  1374. (in the appropriate sense), then @i{predicate} should return @i{false}.
  1375. @b{merge}
  1376. considers two elements @t{x} and @t{y} to be equal if
  1377. @t{(funcall predicate x y)} and
  1378. @t{(funcall predicate y x)} both @i{yield} @i{false}.
  1379. The argument to the @i{key} is the @i{sequence} element.
  1380. Typically, the return value of the @i{key}
  1381. becomes the argument to @i{predicate}.
  1382. If @i{key} is not supplied or @b{nil}, the sequence element itself is used.
  1383. The @i{key} may be executed more than once for each @i{sequence} @i{element},
  1384. and its side effects may occur in any order.
  1385. If @i{key} and @i{predicate} return, then the merging operation
  1386. will terminate. The result of merging two @i{sequences} @t{x} and @t{y}
  1387. is a new @i{sequence} of type @i{result-type} @t{z},
  1388. such that the length of @t{z} is the sum of the lengths of @t{x}
  1389. and @t{y}, and @t{z} contains all the elements of @t{x} and @t{y}.
  1390. If @t{x1} and @t{x2} are two elements of @t{x}, and @t{x1} precedes
  1391. @t{x2} in @t{x}, then @t{x1} precedes @t{x2} in @t{z}, and similarly for
  1392. elements of @t{y}. In short, @t{z} is an interleaving of @t{x} and @t{y}.
  1393. If @t{x} and @t{y} were correctly sorted according to the
  1394. @i{predicate}, then @t{z} will also be correctly sorted.
  1395. If @t{x} or @t{y} is not so sorted, then @t{z} will not be sorted,
  1396. but will nevertheless be an interleaving of @t{x} and @t{y}.
  1397. The merging operation is guaranteed stable;
  1398. if two or more elements are considered equal by the @i{predicate},
  1399. then the elements from @i{sequence-1} will
  1400. precede those from @i{sequence-2} in the result.
  1401. @i{sequence-1} and/or @i{sequence-2} may be destroyed.
  1402. If the @i{result-type} is a @i{subtype} of @b{list},
  1403. the result will be a @i{list}.
  1404. If the @i{result-type} is a @i{subtype} of @b{vector},
  1405. then if the implementation can determine the element type specified
  1406. for the @i{result-type}, the element type of the resulting array
  1407. is the result of @i{upgrading} that element type; or, if the
  1408. implementation can determine that the element type is unspecified (or @t{*}),
  1409. the element type of the resulting array is @b{t};
  1410. otherwise, an error is signaled.
  1411. @subsubheading Examples::
  1412. @example
  1413. (setq test1 (list 1 3 4 6 7))
  1414. (setq test2 (list 2 5 8))
  1415. (merge 'list test1 test2 #'<) @result{} (1 2 3 4 5 6 7 8)
  1416. (setq test1 (copy-seq "BOY"))
  1417. (setq test2 (copy-seq :nosy"))
  1418. (merge 'string test1 test2 #'char-lessp) @result{} "BnOosYy"
  1419. (setq test1 (vector ((red . 1) (blue . 4))))
  1420. (setq test2 (vector ((yellow . 2) (green . 7))))
  1421. (merge 'vector test1 test2 #'< :key #'cdr)
  1422. @result{} #((RED . 1) (YELLOW . 2) (BLUE . 4) (GREEN . 7))
  1423. @end example
  1424. @example
  1425. (merge '(vector * 4) '(1 5) '(2 4 6) #'<) should signal an error
  1426. @end example
  1427. @subsubheading Exceptional Situations::
  1428. An error must be signaled if the @i{result-type} is neither
  1429. a @i{recognizable subtype} of @b{list},
  1430. nor a @i{recognizable subtype} of @b{vector}.
  1431. An error of @i{type} @b{type-error} should be signaled
  1432. if @i{result-type} specifies the number of elements
  1433. and the sum of the lengths of @i{sequence-1} and @i{sequence-2}
  1434. is different from that number.
  1435. @subsubheading See Also::
  1436. @ref{sort; stable-sort}
  1437. ,
  1438. @b{stable-sort},
  1439. @ref{Compiler Terminology},
  1440. @ref{Traversal Rules and Side Effects}
  1441. @node remove, remove-duplicates, merge, Sequences Dictionary
  1442. @subsection remove, remove-if, remove-if-not,
  1443. @subheading delete, delete-if, delete-if-not
  1444. @flushright
  1445. @i{[Function]}
  1446. @end flushright
  1447. @code{remove} @i{item sequence {&key} from-end test test-not start end count key} @result{} @i{result-sequence}
  1448. @code{remove-if} @i{test sequence {&key} from-end start end count key} @result{} @i{result-sequence}
  1449. @code{remove-if-not} @i{test sequence {&key} from-end start end count key} @result{} @i{result-sequence}
  1450. @code{delete} @i{item sequence {&key} from-end test test-not start end count key} @result{} @i{result-sequence}
  1451. @code{delete-if} @i{test sequence {&key} from-end start end count key} @result{} @i{result-sequence}
  1452. @code{delete-if-not} @i{test sequence {&key} from-end start end count key} @result{} @i{result-sequence}
  1453. @subsubheading Arguments and Values::
  1454. @i{item}---an @i{object}.
  1455. @i{sequence}---a @i{proper sequence}.
  1456. @i{test}---a @i{designator} for a @i{function}
  1457. of one @i{argument} that returns a @i{generalized boolean}.
  1458. @i{from-end}---a @i{generalized boolean}.
  1459. The default is @i{false}.
  1460. @i{test}---a @i{designator} for a @i{function} of two @i{arguments}
  1461. that returns a @i{generalized boolean}.
  1462. @i{test-not}---a @i{designator} for
  1463. a @i{function} of two @i{arguments}
  1464. that returns a @i{generalized boolean}.
  1465. @i{start}, @i{end}---@i{bounding index designators} of @i{sequence}.
  1466. The defaults for @i{start} and @i{end} are @t{0} and @b{nil}, respectively.
  1467. @i{count}---an @i{integer} or @b{nil}.
  1468. The default is @b{nil}.
  1469. @i{key}---a @i{designator} for a @i{function} of one argument,
  1470. or @b{nil}.
  1471. @i{result-sequence}---a @i{sequence}.
  1472. @subsubheading Description::
  1473. @b{remove}, @b{remove-if}, and @b{remove-if-not}
  1474. return a @i{sequence} from which
  1475. the elements that @i{satisfy the test}
  1476. have been removed.
  1477. @b{delete}, @b{delete-if}, and @b{delete-if-not}
  1478. are like @b{remove}, @b{remove-if}, and
  1479. @b{remove-if-not} respectively,
  1480. but they may modify @i{sequence}.
  1481. If @i{sequence} is a @i{vector}, the result is a
  1482. @i{vector} that has the same
  1483. @i{actual array element type} as @i{sequence}.
  1484. The result might or might not be simple, and
  1485. might or might not be @i{identical}
  1486. to @i{sequence}.
  1487. If @i{sequence} is a @i{list}, the result is a @i{list}.
  1488. Supplying a @i{from-end} of @i{true} matters only when the
  1489. @i{count} is provided; in that case only the rightmost @i{count} elements
  1490. @i{satisfying the test} are deleted.
  1491. @i{Count}, if supplied, limits the number of elements
  1492. removed or deleted; if more than @i{count} elements @i{satisfy the test},
  1493. then of these elements only the leftmost or rightmost, depending on
  1494. @i{from-end},
  1495. are deleted or removed,
  1496. as many as specified by @i{count}.
  1497. If @i{count} is supplied and negative,
  1498. the behavior is as if zero had been supplied instead.
  1499. If @i{count} is @b{nil}, all matching items are affected.
  1500. For all these functions,
  1501. elements
  1502. not removed or deleted occur in the same order in the result
  1503. as they did in @i{sequence}.
  1504. @b{remove}, @b{remove-if}, @b{remove-if-not} return
  1505. a @i{sequence}
  1506. of the same @i{type} as @i{sequence}
  1507. that has the same elements except that those in the subsequence
  1508. @i{bounded} by @i{start} and @i{end} and @i{satisfying the test}
  1509. have been removed.
  1510. This is a non-destructive operation. If any
  1511. elements need to be removed, the result will be a copy.
  1512. The result of @b{remove} may share
  1513. with @i{sequence};
  1514. the result may be @i{identical} to the input @i{sequence}
  1515. if no elements need to be removed.
  1516. @b{delete}, @b{delete-if}, and @b{delete-if-not}
  1517. return a @i{sequence}
  1518. of the same @i{type} as @i{sequence}
  1519. that has the same elements except that those in the subsequence
  1520. @i{bounded} by @i{start} and @i{end} and @i{satisfying the test}
  1521. have been deleted.
  1522. @i{Sequence} may be destroyed and used to construct
  1523. the result; however, the result might or might not be @i{identical}
  1524. to @i{sequence}.
  1525. @b{delete}, when @i{sequence} is a @i{list}, is permitted to
  1526. @b{setf} any part, @b{car} or @b{cdr}, of the
  1527. top-level list structure in that @i{sequence}.
  1528. When @i{sequence} is a @i{vector}, @b{delete} is
  1529. permitted to change the dimensions of the @i{vector}
  1530. and to slide its elements into new positions without
  1531. permuting them to produce the resulting @i{vector}.
  1532. @b{delete-if} is constrained to behave exactly as follows:
  1533. @example
  1534. (delete nil @i{sequence}
  1535. :test #'(lambda (ignore @i{item}) (funcall @i{test} @i{item}))
  1536. ...)
  1537. @end example
  1538. @subsubheading Examples::
  1539. @example
  1540. (remove 4 '(1 3 4 5 9)) @result{} (1 3 5 9)
  1541. (remove 4 '(1 2 4 1 3 4 5)) @result{} (1 2 1 3 5)
  1542. (remove 4 '(1 2 4 1 3 4 5) :count 1) @result{} (1 2 1 3 4 5)
  1543. (remove 4 '(1 2 4 1 3 4 5) :count 1 :from-end t) @result{} (1 2 4 1 3 5)
  1544. (remove 3 '(1 2 4 1 3 4 5) :test #'>) @result{} (4 3 4 5)
  1545. (setq lst '(list of four elements)) @result{} (LIST OF FOUR ELEMENTS)
  1546. (setq lst2 (copy-seq lst)) @result{} (LIST OF FOUR ELEMENTS)
  1547. (setq lst3 (delete 'four lst)) @result{} (LIST OF ELEMENTS)
  1548. (equal lst lst2) @result{} @i{false}
  1549. (remove-if #'oddp '(1 2 4 1 3 4 5)) @result{} (2 4 4)
  1550. (remove-if #'evenp '(1 2 4 1 3 4 5) :count 1 :from-end t)
  1551. @result{} (1 2 4 1 3 5)
  1552. (remove-if-not #'evenp '(1 2 3 4 5 6 7 8 9) :count 2 :from-end t)
  1553. @result{} (1 2 3 4 5 6 8)
  1554. (setq tester (list 1 2 4 1 3 4 5)) @result{} (1 2 4 1 3 4 5)
  1555. (delete 4 tester) @result{} (1 2 1 3 5)
  1556. (setq tester (list 1 2 4 1 3 4 5)) @result{} (1 2 4 1 3 4 5)
  1557. (delete 4 tester :count 1) @result{} (1 2 1 3 4 5)
  1558. (setq tester (list 1 2 4 1 3 4 5)) @result{} (1 2 4 1 3 4 5)
  1559. (delete 4 tester :count 1 :from-end t) @result{} (1 2 4 1 3 5)
  1560. (setq tester (list 1 2 4 1 3 4 5)) @result{} (1 2 4 1 3 4 5)
  1561. (delete 3 tester :test #'>) @result{} (4 3 4 5)
  1562. (setq tester (list 1 2 4 1 3 4 5)) @result{} (1 2 4 1 3 4 5)
  1563. (delete-if #'oddp tester) @result{} (2 4 4)
  1564. (setq tester (list 1 2 4 1 3 4 5)) @result{} (1 2 4 1 3 4 5)
  1565. (delete-if #'evenp tester :count 1 :from-end t) @result{} (1 2 4 1 3 5)
  1566. (setq tester (list 1 2 3 4 5 6)) @result{} (1 2 3 4 5 6)
  1567. (delete-if #'evenp tester) @result{} (1 3 5)
  1568. tester @result{} @i{implementation-dependent}
  1569. @end example
  1570. @example
  1571. (setq foo (list 'a 'b 'c)) @result{} (A B C)
  1572. (setq bar (cdr foo)) @result{} (B C)
  1573. (setq foo (delete 'b foo)) @result{} (A C)
  1574. bar @result{} ((C)) or ...
  1575. (eq (cdr foo) (car bar)) @result{} T or ...
  1576. @end example
  1577. @subsubheading Side Effects::
  1578. For @b{delete}, @b{delete-if}, and @b{delete-if-not},
  1579. @i{sequence} may be destroyed and used to construct the result.
  1580. @subsubheading Exceptional Situations::
  1581. Should be prepared to signal an error of @i{type} @b{type-error}
  1582. if @i{sequence} is not a @i{proper sequence}.
  1583. @subsubheading See Also::
  1584. @ref{Compiler Terminology},
  1585. @ref{Traversal Rules and Side Effects}
  1586. @subsubheading Notes::
  1587. The @t{:test-not} @i{argument} is deprecated.
  1588. The functions @b{delete-if-not} and @b{remove-if-not} are deprecated.
  1589. @node remove-duplicates, , remove, Sequences Dictionary
  1590. @subsection remove-duplicates, delete-duplicates [Function]
  1591. @code{remove-duplicates} @i{sequence {&key}
  1592. from-end test test-not
  1593. start end key}@*
  1594. @result{} @i{result-sequence}
  1595. @code{delete-duplicates} @i{sequence {&key}
  1596. from-end test test-not
  1597. start end key}@*
  1598. @result{} @i{result-sequence}
  1599. @subsubheading Arguments and Values::
  1600. @i{sequence}---a @i{proper sequence}.
  1601. @i{from-end}---a @i{generalized boolean}.
  1602. The default is @i{false}.
  1603. @i{test}---a @i{designator} for a @i{function} of two @i{arguments}
  1604. that returns a @i{generalized boolean}.
  1605. @i{test-not}---a @i{designator} for
  1606. a @i{function} of two @i{arguments}
  1607. that returns a @i{generalized boolean}.
  1608. @i{start}, @i{end}---@i{bounding index designators} of @i{sequence}.
  1609. The defaults for @i{start} and @i{end} are @t{0} and @b{nil}, respectively.
  1610. @i{key}---a @i{designator} for a @i{function} of one argument,
  1611. or @b{nil}.
  1612. @i{result-sequence}---a @i{sequence}.
  1613. @subsubheading Description::
  1614. @b{remove-duplicates} returns a modified copy of @i{sequence}
  1615. from which any element that matches another element occurring in
  1616. @i{sequence} has been removed.
  1617. If @i{sequence} is a @i{vector}, the result is a
  1618. @i{vector} that has the same
  1619. @i{actual array element type} as @i{sequence}.
  1620. The result might or might not be simple, and
  1621. might or might not be @i{identical}
  1622. to @i{sequence}.
  1623. If @i{sequence} is a @i{list}, the result is a @i{list}.
  1624. @b{delete-duplicates} is like @b{remove-duplicates},
  1625. but @b{delete-duplicates} may modify @i{sequence}.
  1626. The elements of @i{sequence} are compared @i{pairwise}, and if any two match,
  1627. then the one occurring earlier in @i{sequence}
  1628. is discarded, unless @i{from-end} is @i{true}, in which case the one
  1629. later in @i{sequence} is discarded.
  1630. @b{remove-duplicates} and @b{delete-duplicates}
  1631. return a @i{sequence} of the same @i{type} as
  1632. @i{sequence} with enough elements removed so that no two of the remaining
  1633. elements match. The order of the elements remaining in the result
  1634. is the same as the order in which they appear in @i{sequence}.
  1635. @b{remove-duplicates} returns a @i{sequence}
  1636. that may share
  1637. with @i{sequence} or may be @i{identical} to @i{sequence}
  1638. if no elements need to be removed.
  1639. @b{delete-duplicates}, when @i{sequence} is a @i{list},
  1640. is permitted to @b{setf} any part, @b{car} or @b{cdr},
  1641. of the top-level list structure in that @i{sequence}.
  1642. When @i{sequence} is a @i{vector}, @b{delete-duplicates}
  1643. is permitted to change the dimensions of the @i{vector}
  1644. and to slide its elements into new positions without
  1645. permuting them to produce the resulting @i{vector}.
  1646. @subsubheading Examples::
  1647. @example
  1648. (remove-duplicates "aBcDAbCd" :test #'char-equal :from-end t) @result{} "aBcD"
  1649. (remove-duplicates '(a b c b d d e)) @result{} (A C B D E)
  1650. (remove-duplicates '(a b c b d d e) :from-end t) @result{} (A B C D E)
  1651. (remove-duplicates '((foo #\a) (bar #\%) (baz #\A))
  1652. :test #'char-equal :key #'cadr) @result{} ((BAR #\%) (BAZ #\A))
  1653. (remove-duplicates '((foo #\a) (bar #\%) (baz #\A))
  1654. :test #'char-equal :key #'cadr :from-end t) @result{} ((FOO #\a) (BAR #\%))
  1655. (setq tester (list 0 1 2 3 4 5 6))
  1656. (delete-duplicates tester :key #'oddp :start 1 :end 6) @result{} (0 4 5 6)
  1657. @end example
  1658. @subsubheading Side Effects::
  1659. @b{delete-duplicates} might destructively modify @i{sequence}.
  1660. @subsubheading Exceptional Situations::
  1661. Should signal an error of @i{type} @b{type-error}
  1662. if @i{sequence} is not a @i{proper sequence}.
  1663. @subsubheading See Also::
  1664. @ref{Compiler Terminology},
  1665. @ref{Traversal Rules and Side Effects}
  1666. @subsubheading Notes::
  1667. The @t{:test-not} @i{argument} is deprecated.
  1668. These functions are useful for converting @i{sequence} into a canonical
  1669. form suitable for representing a set.
  1670. @c end of including dict-sequences
  1671. @c %**end of chapter