klisp

an open source interpreter for the Kernel Programming Language.
git clone http://git.hanabi.in/repos/klisp.git
Log | Files | Refs | README

commit 93ea6443db84c52dbe11fa3176526859fc617f2f
parent 39ac8f8ce0ce5f77ba9ba20b4ab4df5201fa75ad
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Wed,  1 Jun 2011 19:02:48 -0300

Completed the pairs & lists module in the manual.

Diffstat:
Mmanual/html/Index.html | 11+++++++++++
Mmanual/html/index.html | 4++--
Mmanual/klisp.info | 165+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
Mmanual/src/klisp.texi | 4++--
Mmanual/src/pairs_lists.texi | 151++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
5 files changed, 307 insertions(+), 28 deletions(-)

diff --git a/manual/html/Index.html b/manual/html/Index.html @@ -42,7 +42,10 @@ Up:&nbsp;<a rel="up" accesskey="u" href="index.html#Top">Top</a> <li><a href="Control.html#index-g_t_0024sequence-29"><code>$sequence</code></a>: <a href="Control.html#Control">Control</a></li> <li><a href="Booleans.html#index-and_003f-15"><code>and?</code></a>: <a href="Booleans.html#Booleans">Booleans</a></li> <li><a href="Pairs-and-lists.html#index-append-80"><code>append</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> +<li><a href="Pairs-and-lists.html#index-append_0021-88"><code>append!</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> <li><a href="A-Sample-Applicative-Description.html#index-applicative-descriptions-8">applicative descriptions</a>: <a href="A-Sample-Applicative-Description.html#A-Sample-Applicative-Description">A Sample Applicative Description</a></li> +<li><a href="Pairs-and-lists.html#index-assoc-83"><code>assoc</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> +<li><a href="Pairs-and-lists.html#index-assq-90"><code>assq</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> <li><a href="Booleans.html#index-boolean_003f-13"><code>boolean?</code></a>: <a href="Booleans.html#Booleans">Booleans</a></li> <li><a href="Booleans.html#index-booleans-12">booleans</a>: <a href="Booleans.html#Booleans">Booleans</a></li> <li><a href="Pairs-and-lists.html#index-caaaar-58"><code>caaaar</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> @@ -77,7 +80,9 @@ Up:&nbsp;<a rel="up" accesskey="u" href="index.html#Top">Top</a> <li><a href="Pairs-and-lists.html#index-cdr-45"><code>cdr</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> <li><a href="Pairs-and-lists.html#index-cons-38"><code>cons</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> <li><a href="Control.html#index-control-26">control</a>: <a href="Control.html#Control">Control</a></li> +<li><a href="Pairs-and-lists.html#index-copy_002des-89"><code>copy-es</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> <li><a href="Pairs-and-lists.html#index-copy_002des_002dimmutable_0021-41"><code>copy-es-immutable!</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> +<li><a href="Pairs-and-lists.html#index-countable_002dlist_003f-86"><code>countable-list?</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> <li><a href="Format-of-Descriptions.html#index-description-format-7">description format</a>: <a href="Format-of-Descriptions.html#Format-of-Descriptions">Format of Descriptions</a></li> <li><a href="Evaluation-Notation.html#index-documentation-notation-4">documentation notation</a>: <a href="Evaluation-Notation.html#Evaluation-Notation">Evaluation Notation</a></li> <li><a href="Pairs-and-lists.html#index-empty-list-34">empty list</a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> @@ -87,6 +92,8 @@ Up:&nbsp;<a rel="up" accesskey="u" href="index.html#Top">Top</a> <li><a href="Equivalence.html#index-equivalence-19">equivalence</a>: <a href="Equivalence.html#Equivalence">Equivalence</a></li> <li><a href="Error-Messages.html#index-error-message-notation-6">error message notation</a>: <a href="Error-Messages.html#Error-Messages">Error Messages</a></li> <li><a href="Evaluation-Notation.html#index-evaluation-notation-3">evaluation notation</a>: <a href="Evaluation-Notation.html#Evaluation-Notation">Evaluation Notation</a></li> +<li><a href="Pairs-and-lists.html#index-filter-82"><code>filter</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> +<li><a href="Pairs-and-lists.html#index-finite_002dlist_003f-85"><code>finite-list?</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> <li><a href="Some-Terms.html#index-fonts-2">fonts</a>: <a href="Some-Terms.html#Some-Terms">Some Terms</a></li> <li><a href="A-Sample-Applicative-Description.html#index-foo-11"><code>foo</code></a>: <a href="A-Sample-Applicative-Description.html#A-Sample-Applicative-Description">A Sample Applicative Description</a></li> <li><a href="Control.html#index-for_002deach-31"><code>for-each</code></a>: <a href="Control.html#Control">Control</a></li> @@ -96,10 +103,13 @@ Up:&nbsp;<a rel="up" accesskey="u" href="index.html#Top">Top</a> <li><a href="Pairs-and-lists.html#index-length-78"><code>length</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> <li><a href="Pairs-and-lists.html#index-list-42"><code>list</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> <li><a href="Pairs-and-lists.html#index-list_002a-43"><code>list*</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> +<li><a href="Pairs-and-lists.html#index-list_002dneighbors-81"><code>list-neighbors</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> <li><a href="Pairs-and-lists.html#index-list_002dref-79"><code>list-ref</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> <li><a href="Pairs-and-lists.html#index-list_002dtail-75"><code>list-tail</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> <li><a href="Pairs-and-lists.html#index-lists-35">lists</a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> <li><a href="Pairs-and-lists.html#index-map-77"><code>map</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> +<li><a href="Pairs-and-lists.html#index-member_003f-84"><code>member?</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> +<li><a href="Pairs-and-lists.html#index-memq_003f-91"><code>memq?</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> <li><a href="Pairs-and-lists.html#index-nil-33">nil</a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> <li><a href="Booleans.html#index-not_003f-14"><code>not?</code></a>: <a href="Booleans.html#Booleans">Booleans</a></li> <li><a href="Pairs-and-lists.html#index-null_003f-37"><code>null?</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> @@ -109,6 +119,7 @@ Up:&nbsp;<a rel="up" accesskey="u" href="index.html#Top">Top</a> <li><a href="Pairs-and-lists.html#index-pair_003f-36"><code>pair?</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> <li><a href="Pairs-and-lists.html#index-pairs-32">pairs</a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> <li><a href="Printing-Notation.html#index-printing-notation-5">printing notation</a>: <a href="Printing-Notation.html#Printing-Notation">Printing Notation</a></li> +<li><a href="Pairs-and-lists.html#index-reduce-87"><code>reduce</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> <li><a href="Pairs-and-lists.html#index-set_002dcar_0021-39"><code>set-car!</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> <li><a href="Pairs-and-lists.html#index-set_002dcdr_0021-40"><code>set-cdr!</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li> <li><a href="Symbols.html#index-string_002d_003esymbol-25"><code>string-&gt;symbol</code></a>: <a href="Symbols.html#Symbols">Symbols</a></li> diff --git a/manual/html/index.html b/manual/html/index.html @@ -37,10 +37,10 @@ Up:&nbsp;<a rel="up" accesskey="u" href="../index.html#dir">(dir)</a> <li><a accesskey="1" href="License.html#License">License</a>: Conditions for copying and changing klisp. <li><a accesskey="2" href="Introduction.html#Introduction">Introduction</a>: Introduction and conventions used. <!-- TODO lisp types and other introductions --> -<li><a accesskey="3" href="Booleans.html#Booleans">Booleans</a>: Boolean module features. +<li><a accesskey="3" href="Booleans.html#Booleans">Booleans</a>: Booleans module features. <li><a accesskey="4" href="Equivalence.html#Equivalence">Equivalence</a>: Equivalence under mutation &amp; Equivalence up to mutation module features. -<li><a accesskey="5" href="Symbols.html#Symbols">Symbols</a>: Symbol module features. +<li><a accesskey="5" href="Symbols.html#Symbols">Symbols</a>: Symbols module features. <li><a accesskey="6" href="Control.html#Control">Control</a>: Control module features. <li><a accesskey="7" href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a>: Pairs and lists and Pair mutation module features. <!-- TODO complete --> diff --git a/manual/klisp.info b/manual/klisp.info @@ -26,10 +26,10 @@ in part. * License:: Conditions for copying and changing klisp. * Introduction:: Introduction and conventions used. -* Booleans:: Boolean module features. +* Booleans:: Booleans module features. * Equivalence:: Equivalence under mutation & Equivalence up to mutation module features. -* Symbols:: Symbol module features. +* Symbols:: Symbols module features. * Control:: Control module features. * Pairs and lists:: Pairs and lists and Pair mutation module features. * Index:: Index including concepts, functions, variables, @@ -736,6 +736,120 @@ output using, modulo whitespace, external representation `(1 2 3)'. (append () h . t) == (append h . t) (append (cons a b) h . t) == (cons a (append b h . t)) + -- Applicative: list-neighbors (list-neighbors list) + The `list-neighbors' applicative constructs and returns a list of + all the consecutive sublists of `list' of length 2, in order. If + `list' is nil, the result is nil. If `list' is non-nil, the + length of the result is one less than the length of `list'. If + `list' is cyclic, the result is structurally isomorphic to it + (i.e., has the same acyclic prefix length and cycle length). + + For example: + (list-neighbors (list 1 2 3 4)) => ((1 2) (2 3) (3 4)) + + -- Applicative: filter (filter applicative list) + Applicative `filter' passes each of the elements of `list' as an + argument to `applicative', one at a time in no particular order, + using a fresh empty environment for each call. The result of each + call to `applicative' must be boolean, otherwise an error is + signaled. `filter' constructs and returns a list of all elements + of `list' on which `applicative' returned true, in the same order + as in `list'. `applicative' is called exactly as many times as + there are pairs in `list'. The resultant list has a cycle + containing exactly those elements accepted by `applicative' that + were in the cycle of `list'; if there were no such elements, the + result is acyclic. + + -- Applicative: assoc (assoc object pairs) + Applicative `assoc' returns the first element of `pairs' whose car + is `equal?' to `object'. If there is no such element in `pairs', + nil is returned. + + -- Applicative: member? (member? object list) + Applicative `member?' is a predicate that returns true iff some + element of `list' is `equal?' to `object'. + + -- Applicative: finite-list? (finite-list? . objects) + This is the type predicate for type finite-list. `finite-list?' + returns true iff all the objects in `objects' are acyclic lists. + + -- Applicative: countable-list? (countable-list? . objects) + This is the type predicate for type list. `countable-list?' + returns true iff all the objects in `objects' are lists. + + -- Applicative: reduce (reduce list binary identity [precycle incycle + postcycle]) + `binary' should be an applicative. If the short form is used, + `list' should be an acyclic. If the long form is used, `precycle', + `incycle', and `postcycle' should be applicatives. + + If `list' is empty, applicative `reduce' returns `identity'. If + `list' is nonempty but acyclic, applicative `reduce' uses binary + operation `binary' to merge all the elements of `list' into a + single object, using any associative grouping of the elements. + That is, the sequence of objects initially found in `list' is + repeatedly decremented in length by applying `binary' to a list of + any two consecutive objects, replacing those two objects with the + result at the point in the sequence where they occurred; and when + the sequence contains only one object, that object is returned. + If `list' is cyclic, the long form must be used. The elements of + the cycle are passed, one at a time (but just once for each + position in the cycle), as arguments to unary applicative + `precycle'; the finite, cyclic sequence of results from `precycle' + is reduced using binary applicative `incycle'; and the result from + reducing the cycle is passed as an argument to unary applicative + `postcycle'. Binary operation `binary' is used to reduce the + sequence consisting of the elements of the acyclic prefix of + `list' followed by the result returned by `postcycle'. The only + constraint on the order of calls to the applicatives is that each + call must be made before its result is needed (thus, parts of the + reduction of the acyclic prefix may occur before the contribution + from the cycle has been completed). + + Each call to `binary', `precycle', `incycle', or `postcycle' uses + the dynamic environment of the call to `reduce'. + + If `list' is acyclic with length `n >= 1', `binary' is called `n - + 1' times. If `list' is cyclic with acyclic prefix length `a' and + cycle length `c', `binary' is called `a' times; `precycle', `c' + times; `incycle', `c - 1' times; and `postcycle', once. + + -- Applicative: append! (append! . lists) + `lists' must be a nonempty list; its first element must be an + acyclic nonempty list, and all of its elements except the last + element (if any) must be acyclic lists. + + The `append!' applicative sets the cdr of the last pair in each + nonempty list argument to refer to the next non-nil argument, + except that if there is a last non-nil argument, it isn’t mutated. + It is an error for any two of the list arguments to have the same + last pair. The result returned by this applicative is inert. + + The following equivalences hold: + (append! v) == #inert + (append! u v . w) == ($sequence (append! u v) (append! u . w)) + + -- Applicative: copy-es (copy-es object) + Briefly, applicative `copy-es' returns an object initially + `equal?' to `object' with a freshly constructed evaluation + structure made up of mutable pairs. If `object' is not a pair, + the applicative returns `object'. If `object' is a pair, the + applicative returns a freshly constructed pair whose car and cdr + would be suitable results for `(copy-es (car object))' and + `(copy-es (cdr object))', respectively. Further, the evaluation + structure of the returned value is structurally isomorphic to that + of `object' at the time of copying, with corresponding non-pair + referents being `eq?'. + + -- Applicative: assq (assq object pairs) + Applicative `assq' returns the first element of `pairs' whose car + is `eq?' to `object'. If there is no such element in `pairs', nil + is returned. + + -- Applicative: memq? (memq? object list) + Applicative `memq?' is a predicate that returns true iff some + element of `list' is `eq?' to `object'. +  File: klisp.info, Node: Index, Next: (dir), Prev: Pairs and lists, Up: Top @@ -752,8 +866,11 @@ Index * $sequence: Control. (line 23) * and?: Booleans. (line 20) * append: Pairs and lists. (line 208) +* append!: Pairs and lists. (line 306) * applicative descriptions: A Sample Applicative Description. (line 6) +* assoc: Pairs and lists. (line 252) +* assq: Pairs and lists. (line 333) * boolean?: Booleans. (line 12) * booleans: Booleans. (line 6) * caaaar: Pairs and lists. (line 101) @@ -788,7 +905,9 @@ Index * cdr: Pairs and lists. (line 86) * cons: Pairs and lists. (line 35) * control: Control. (line 6) +* copy-es: Pairs and lists. (line 321) * copy-es-immutable!: Pairs and lists. (line 49) +* countable-list?: Pairs and lists. (line 265) * description format: Format of Descriptions. (line 6) * documentation notation: Evaluation Notation. (line 6) @@ -799,6 +918,8 @@ Index * equivalence: Equivalence. (line 6) * error message notation: Error Messages. (line 6) * evaluation notation: Evaluation Notation. (line 6) +* filter: Pairs and lists. (line 239) +* finite-list?: Pairs and lists. (line 261) * fonts: Some Terms. (line 13) * foo: A Sample Applicative Description. (line 15) @@ -809,10 +930,13 @@ Index * length: Pairs and lists. (line 191) * list: Pairs and lists. (line 72) * list*: Pairs and lists. (line 78) +* list-neighbors: Pairs and lists. (line 228) * list-ref: Pairs and lists. (line 198) * list-tail: Pairs and lists. (line 147) * lists: Pairs and lists. (line 6) * map: Pairs and lists. (line 169) +* member?: Pairs and lists. (line 257) +* memq?: Pairs and lists. (line 338) * nil: Pairs and lists. (line 6) * not?: Booleans. (line 16) * null?: Pairs and lists. (line 31) @@ -824,6 +948,7 @@ Index * pair?: Pairs and lists. (line 27) * pairs: Pairs and lists. (line 6) * printing notation: Printing Notation. (line 6) +* reduce: Pairs and lists. (line 270) * set-car!: Pairs and lists. (line 41) * set-cdr!: Pairs and lists. (line 42) * string->symbol: Symbols. (line 20) @@ -835,23 +960,23 @@ Index  Tag Table: Node: Top302 -Node: License1209 -Node: Introduction2880 -Node: Caveats5703 -Node: Kernel History6489 -Node: Conventions7934 -Node: Some Terms8605 -Node: Evaluation Notation9276 -Node: Printing Notation10297 -Node: Error Messages10773 -Node: Format of Descriptions11421 -Node: A Sample Applicative Description11985 -Node: Acknowledgements13748 -Node: Booleans14134 -Node: Equivalence16676 -Node: Symbols17469 -Node: Control18834 -Node: Pairs and lists21151 -Node: Index32148 +Node: License1211 +Node: Introduction2882 +Node: Caveats5705 +Node: Kernel History6491 +Node: Conventions7936 +Node: Some Terms8607 +Node: Evaluation Notation9278 +Node: Printing Notation10299 +Node: Error Messages10775 +Node: Format of Descriptions11423 +Node: A Sample Applicative Description11987 +Node: Acknowledgements13750 +Node: Booleans14136 +Node: Equivalence16678 +Node: Symbols17471 +Node: Control18836 +Node: Pairs and lists21153 +Node: Index38167  End Tag Table diff --git a/manual/src/klisp.texi b/manual/src/klisp.texi @@ -72,10 +72,10 @@ in part. * License:: Conditions for copying and changing klisp. * Introduction:: Introduction and conventions used. @c TODO lisp types and other introductions -* Booleans:: Boolean module features. +* Booleans:: Booleans module features. * Equivalence:: Equivalence under mutation & Equivalence up to mutation module features. -* Symbols:: Symbol module features. +* Symbols:: Symbols module features. * Control:: Control module features. * Pairs and lists:: Pairs and lists and Pair mutation module features. @c TODO complete diff --git a/manual/src/pairs_lists.texi b/manual/src/pairs_lists.texi @@ -105,12 +105,10 @@ operand tree, regardless of whether that tree is or is not a list. @deffnx Applicative cdr (cdr pair) These applicatives return, respectively, the car and cdr of @code{pair}. @end deffn -@c 2 levels @deffn Applicative caar (caar pair) @deffnx Applicative cadr (cadr pair) @deffnx Applicative cdar (cdar pair) @deffnx Applicative cddr (cddr pair) -@c 3 levels @deffnx Applicative caaar (caaar pair) @deffnx Applicative caadr (caadr pair) @deffnx Applicative cadar (cadar pair) @@ -119,7 +117,6 @@ These applicatives return, respectively, the car and cdr of @code{pair}. @deffnx Applicative cdadr (cdadr pair) @deffnx Applicative cddar (cddar pair) @deffnx Applicative cdddr (cdddr pair) -@c 3 levels @deffnx Applicative caaaar (caaaar pair) @deffnx Applicative caaadr (caaadr pair) @deffnx Applicative caadar (caadar pair) @@ -128,7 +125,6 @@ These applicatives return, respectively, the car and cdr of @code{pair}. @deffnx Applicative cadadr (cadadr pair) @deffnx Applicative caddar (caddar pair) @deffnx Applicative cadddr (cadddr pair) - @deffnx Applicative cdaaar (cdaaar pair) @deffnx Applicative cdaadr (cdaadr pair) @deffnx Applicative cdadar (cdadar pair) @@ -269,4 +265,151 @@ The following equivalences hold: (append () h . t) @equiv{} (append h . t) (append (cons a b) h . t) @equiv{} (cons a (append b h . t)) @end example +@c TODO add xref/comp to append +@end deffn + +@deffn Applicative list-neighbors (list-neighbors list) + The @code{list-neighbors} applicative constructs and returns a list +of all the consecutive sublists of @code{list} of length 2, in order. +If @code{list} is nil, the result is nil. If @code{list} is non-nil, +the length of the result is one less than the length of +@code{list}. If @code{list} is cyclic, the result is structurally +isomorphic to it (i.e., has the same acyclic prefix length and cycle +length). +@c TODO add xref to isomorphic + + For example: +@example +(list-neighbors (list 1 2 3 4)) @result{} ((1 2) (2 3) (3 4)) +@end example +@end deffn + +@deffn Applicative filter (filter applicative list) + Applicative @code{filter} passes each of the elements of @code{list} +as an argument to @code{applicative}, one at a time in no particular +order, using a fresh empty environment for each call. The result of +each call to @code{applicative} must be boolean, otherwise an error is +signaled. @code{filter} constructs and returns a list of all elements +of @code{list} on which @code{applicative} returned true, in the same +order as in @code{list}. @code{applicative} is called exactly as many +times as there are pairs in @code{list}. The resultant list has a +cycle containing exactly those elements accepted by @code{applicative} +that were in the cycle of @code{list}; if there were no such elements, +the result is acyclic. +@end deffn + +@deffn Applicative assoc (assoc object pairs) + Applicative @code{assoc} returns the first element of @code{pairs} +whose car is @code{equal?} to @code{object}. If there is no such +element in @code{pairs}, nil is returned. +@c TODO add xref/comp to assq +@c TODO add xref to equal? +@end deffn + +@deffn Applicative member? (member? object list) + Applicative @code{member?} is a predicate that returns true iff some +element of @code{list} is @code{equal?} to @code{object}. +@c TODO add xref/comp to memq +@c TODO add xref to equal? +@end deffn + +@deffn Applicative finite-list? (finite-list? . objects) + This is the type predicate for type finite-list. +@code{finite-list?} returns true iff all the objects in +@code{objects} are acyclic lists. +@end deffn + +@deffn Applicative countable-list? (countable-list? . objects) +This is the type predicate for type list. @code{countable-list?} +returns true iff all the objects in @code{objects} are lists. +@end deffn + +@deffn Applicative reduce (reduce list binary identity [precycle incycle postcycle]) + @code{binary} should be an applicative. If the short form is used, +@code{list} should be an acyclic. If the long form is used, +@code{precycle}, @code{incycle}, and @code{postcycle} should be +applicatives. + + If @code{list} is empty, applicative @code{reduce} returns +@code{identity}. If @code{list} is nonempty but acyclic, applicative +@code{reduce} uses binary operation @code{binary} to merge all the +elements of @code{list} into a single object, using any associative +grouping of the elements. That is, the sequence of objects initially +found in @code{list} is repeatedly decremented in length by applying +@code{binary} to a list of any two consecutive objects, replacing +those two objects with the result at the point in the sequence where +they occurred; and when the sequence contains only one object, that +object is returned. If @code{list} is cyclic, the long form must be +used. The elements of the cycle are passed, one at a time (but just +once for each position in the cycle), as arguments to unary +applicative @code{precycle}; the finite, cyclic sequence of results +from @code{precycle} is reduced using binary applicative +@code{incycle}; and the result from reducing the cycle is passed as an +argument to unary applicative @code{postcycle}. Binary operation +@code{binary} is used to reduce the sequence consisting of the +elements of the acyclic prefix of @code{list} followed by the result +returned by @code{postcycle}. The only constraint on the order of +calls to the applicatives is that each call must be made before its +result is needed (thus, parts of the reduction of the acyclic prefix +may occur before the contribution from the cycle has been completed). + + Each call to @code{binary}, @code{precycle}, @code{incycle}, or +@code{postcycle} uses the dynamic environment of the call to +@code{reduce}. + + If @code{list} is acyclic with length @code{n >= 1}, +@code{binary} is called @code{n - 1} times. If @code{list} is cyclic +with acyclic prefix length @code{a} and cycle length @code{c}, +@code{binary} is called @code{a} times; @code{precycle}, @code{c} +times; @code{incycle}, @code{c - 1} times; and @code{postcycle}, once. +@end deffn + +@deffn Applicative append! (append! . lists) + @code{lists} must be a nonempty list; its first element must be an +acyclic nonempty list, and all of its elements except the last element +(if any) must be acyclic lists. + + The @code{append!} applicative sets the cdr of the last pair in each +nonempty list argument to refer to the next non-nil argument, except +that if there is a last non-nil argument, it isn’t mutated. It is an +error for any two of the list arguments to have the same last pair. +The result returned by this applicative is inert. + + The following equivalences hold: +@example +(append! v) @equiv{} #inert +(append! u v . w) @equiv{} ($sequence (append! u v) (append! u . w)) +@end example +@end deffn + +@deffn Applicative copy-es (copy-es object) + Briefly, applicative @code{copy-es} returns an object initially +@code{equal?} to @code{object} with a freshly constructed evaluation +@c TODO add xref to evaluation structure +structure made up of mutable pairs. If @code{object} is not a pair, +the applicative returns @code{object}. If @code{object} is a pair, +the applicative returns a freshly constructed pair whose car and cdr +would be suitable results for @code{(copy-es (car object))} and +@code{(copy-es (cdr object))}, respectively. Further, the evaluation +@c TODO add xref to isomorphic +structure of the returned value is structurally isomorphic to that of +@code{object} at the time of copying, with corresponding non-pair +referents being @code{eq?}. +@c TODO add xref/comp to copy-es-immutable and the reverse too! +@c TODO add xref to eq?/equal? +@end deffn + +@deffn Applicative assq (assq object pairs) + Applicative @code{assq} returns the first element of @code{pairs} +whose car is @code{eq?} to @code{object}. If there is no such element +in @code{pairs}, nil is returned. +@c TODO add xref/comp to assoc +@c TODO add xref to eq? +@end deffn + +@deffn Applicative memq? (memq? object list) + Applicative @code{memq?} is a predicate that returns true iff some +element of @code{list} is @code{eq?} to @code{object}. +@c TODO add xref/comp to member? +@c TODO add xref to eq? @end deffn