(index ("ipair" 0) ("ilist" 501) ("xipair" 697) ("ipair*" 993) ("make-ilist" 1277) ("ilist-tabulate" 1564) ("ilist-copy" 1932) ("iiota" 2060) ("proper-ilist?" 2463) ("ilist?" 2463) ("dotted-ilist?" 3049) ("ipair?" 3452) ("null-ilist?" 3819) ("not-ipair?" 4213) ("ilist=" 4488) ("icar" 6213) ("icdr" 6213) ("icaar" 6785) ("icadr" 6785) ("icdddar" 6785) ("icddddr" 6785) ("ilist-ref" 7251) ("ifirst" 7515) ("isecond" 7515) ("ithird" 7515) ("ifourth" 7515) ("ififth" 7515) ("isixth" 7515) ("iseventh" 7515) ("ieigth" 7515) ("ininth" 7515) ("itenth" 7515) ("itake" 8259) ("idrop" 8259) ("ilist-tail" 8259) ("itake-right" 9453) ("idrop-right" 9453) ("isplit-at" 10585) ("ilast" 10872) ("last-ipair" 10872) ("ilength" 11231) ("iappend" 11569) ("iconcatenate" 12377) ("ireverse" 13096) ("iappend-reverse" 13384) ("izip" 14181) ("iunzip1" 14722) ("iunzip2" 14722) ("iunzip3" 14722) ("iunzip4" 14722) ("iunzip5" 14722) ("icount" 15559) ("ifold" 16210) ("ifold-right" 17454) ("ipair-fold" 18495) ("ipair-fold-right" 19093) ("ireduce" 19552) ("ireduce-right" 20995) ("iunfold" 21660) ("iunfold-right" 24016) ("imap" 25590) ("ifor-each" 26340) ("iappend-map" 26994) ("imap-in-order" 27625) ("ipair-for-each" 27966) ("ifilter-map" 28431) ("ifilter" 28775) ("ipartition" 29318) ("iremove" 29957) ("ifind" 30591) ("ifind-tail" 31579) ("itake-while" 32380) ("idrop-while" 32639) ("ispan" 32945) ("ibreak" 32945) ("iany" 33803) ("ievery" 35302) ("ilist-index" 36581) ("imember" 37719) ("imemq" 37719) ("imemv" 37719) ("idelete" 39331) ("idelete-duplicates" 40591) ("iassoc" 42439) ("iassq" 42439) ("iassv" 42439) ("ialist-cons" 44241) ("ialist-delete" 44466) ("replace-icar" 45356) ("replace-icdr" 45553) ("pair->ipair" 45745) ("ipair->pair" 45745) ("list->ilist" 46003) ("ilist->list" 46003) ("tree->itree" 46492) ("itree->tree" 46492) ("gtree->itree" 47113) ("itree->gtree" 47113) ("iapply" 47546))
(def (sig (procedure "(ipair a d)" (id ipair))) (p "The primitive constructor. Returns a newly allocated ipair whose icar is " (tt "a") " and whose icdr is " (tt "d") ". The ipair is guaranteed to be different (in the sense of " (tt "eqv?") ") from every existing object.") (highlight scheme "(ipair 'a '())            ;=> (a)\n(ipair (iq a) (iq b c d)) ;=> ((a) b c d)\n(ipair \"a\" (iq b c))      ;=> (\"a\" b c)\n(ipair 'a 3)              ;=> (a . 3)\n(ipair (iq a b) 'c)       ;=> ((a b ) . c)"))
(def (sig (procedure "(ilist obj ...)" (id ilist))) (p "Returns a newly allocated ilist of its arguments.") (highlight scheme "(ilist 'a (+ 3 4) 'c) ;=>  (a 7 c)\n(ilist)               ;=>  ()"))
(def (sig (procedure "(xipair d a)" (id xipair))) (highlight scheme "(lambda (d a) (ipair a d))") (p "Of utility only as a value to be conveniently passed to higher-order procedures.") (highlight scheme "(xipair (iq b c) 'a) ;=> (a b c)") (p "The name stands for \"eXchanged Immutable PAIR.\""))
(def (sig (procedure "(ipair* elt1 elt2 ...)" (id ipair*))) (p "Like ilist, but the last argument provides the tail of the constructed ilist, returning " (tt "(ipair elt1 (ipair elt2 (ipair ... eltn)))")) (highlight scheme "(ipair* 1 2 3 4) ;=> (1 2 3 . 4)\n(ipair* 1)       ;=> 1"))
(def (sig (procedure "(make-ilist n [fill])" (id make-ilist))) (p "Returns an " (tt "n") "-element ilist, whose elements are all the value fill. If the fill argument is not given, the elements of the ilist may be arbitrary values.") (highlight scheme "(make-ilist 4 'c) ;=> (c c c c)"))
(def (sig (procedure "(ilist-tabulate n init-proc)" (id ilist-tabulate))) (p "Returns an " (tt "n") "-element ilist. Element i of the ilist, where 0 <= i < n, is produced by " (tt "(init-proc i)") ". No guarantee is made about the dynamic order in which " (tt "init-proc") " is applied to these indices.") (highlight scheme "(ilist-tabulate 4 values) ;=> (0 1 2 3)"))
(def (sig (procedure "(ilist-copy dilist)" (id ilist-copy))) (p "Copies the spine of the argument, including the ilist tail."))
(def (sig (procedure "(iiota count [start [step]])" (id iiota))) (p "Returns an ilist containing the elements:") (highlight scheme "(start start+step ... start+(count-1)*step)") (p "The start and step parameters default to 0 and 1, respectively. This procedure takes its name from the APL primitive.") (highlight scheme "(iiota 5)        ;=> (0 1 2 3 4)\n(iiota 5 0 -0.1) ;=> (0 -0.1 -0.2 -0.3 -0.4)"))
(def (sig (procedure "(proper-ilist? x)" (id proper-ilist?)) (procedure "(ilist? x)" (id ilist?))) (p "These identifiers are bound either to the same procedure, or to procedures of equivalent behavior. In either case, true is returned iff " (tt "x") " is a proper ilist — a ()-terminated ilist.") (p "More carefully: The empty list is a proper ilist. An ipair whose icdr is a proper ilist is also a proper ilist. Everything else is a dotted ilist. This includes non-ipair, non-() values (e.g. symbols, numbers, mutable pairs), which are considered to be dotted ilists of length 0."))
(def (sig (procedure "(dotted-ilist? x)" (id dotted-ilist?))) (p "True if " (tt "x") " is a finite, non-nil-terminated ilist. That is, there exists an n >= 0 such that " (tt "(icdrn x)") " is neither an ipair nor (). This includes non-ipair, non-() values (e.g. symbols, numbers), which are considered to be dotted ilists of length 0.") (highlight scheme "(dotted-ilist? x) = (not (proper-ilist? x))"))
(def (sig (procedure "(ipair? obj)" (id ipair?))) (p "Returns " (tt "#t") " if object is an ipair; otherwise " (tt "#f")) (highlight scheme "(ipair? (ipair 'a 'b)) ;=>  #t\n(ipair? (iq a b c))    ;=>  #t\n(ipair? (cons 1 2))    ;=>  #f\n(ipair? '())           ;=>  #f\n(ipair? '#(a b))       ;=>  #f\n(ipair? 7)             ;=>  #f\n(ipair? 'a)            ;=>  #f"))
(def (sig (procedure "(null-ilist? ilist)" (id null-ilist?))) (p (tt "ilist") " is a proper ilist. This procedure returns true if the argument is the empty list (), and false otherwise. It is an error to pass this procedure a value which is not a proper ilist. This procedure is recommended as the termination condition for ilist-processing procedures that are not defined on dotted ilists."))
(def (sig (procedure "(not-ipair? x)" (id not-ipair?))) (highlight scheme "(lambda (x) (not (ipair? x)))") (p "Provided as a procedure as it can be useful as the termination condition for ilist-processing procedures that wish to handle all ilists, both proper and dotted."))
(def (sig (procedure "(ilist= elt= ilist1 ...)" (id ilist=))) (p "Determines ilist equality, given an element-equality procedure. Proper ilist A equals proper ilist B if they are of the same length, and their corresponding elements are equal, as determined by " (tt "elt=") ". If the element-comparison procedure's first argument is from ilisti, then its second argument is from ilisti+1, i.e. it is always called as " (tt "(elt= a b)") " for a an element of ilist A, and b an element of ilist B.") (p "In the n-ary case, every ilisti is compared to ilisti+1 (as opposed, for example, to comparing ilist1 to ilisti, for i>1). If there are no ilist arguments at all, " (tt "ilist=") " simply returns true.") (p "It is an error to apply ilist= to anything except proper ilists. It cannot reasonably be extended to dotted ilists, as it provides no way to specify an equality procedure for comparing the ilist terminators.") (p "Note that the dynamic order in which the " (tt "elt=") " procedure is applied to pairs of elements is not specified. For example, if " (tt "ilist=") " is applied to three ilists, A, B, and C, it may first completely compare A to B, then compare B to C, or it may compare the first elements of A and B, then the first elements of B and C, then the second elements of A and B, and so forth.") (p "The equality procedure must be consistent with eq?. That is, it must be the case that") (highlight scheme "(eq? x y) ;=> (elt= x y).") (p "Note that this implies that two ilists which are eq? are always ilist=, as well; implementations may exploit this fact to \"short-cut\" the element-by-element comparisons.") (highlight scheme "(ilist= eq?)        ;=> #t ;Trivial cases\n(ilist= eq? (iq a)) ;=> #t"))
(def (sig (procedure "(icar ipair)" (id icar)) (procedure "(icdr ipair)" (id icdr))) (p "These procedures return the contents of the " (tt "icar") " and " (tt "icdr") " field of their argument, respectively. Note that it is an error to apply them to the empty ilist.") (highlight scheme "(icar (iq a b c))       ;=>  a\n(icar (iq (a) b c d))   ;=>  (a)\n(icar (ipair 1 2))      ;=>  1\n(icar '())              ;=>  *error*\n\n(icdr (iq a b c))       ;=>  (b c)\n(icdr (iq (a) b c d))   ;=>  (b c d)\n(icdr (ipair 1 2))      ;=>  2\n(icdr '())              ;=>  *error*"))
(def (sig (procedure "(icaar ipair)" (id icaar)) (procedure "(icadr ipair)" (id icadr)) (procedure "(icdddar ipair)" (id icdddar)) (procedure "(icddddr ipair)" (id icddddr))) (p "These procedures are compositions of icar and icdr, where for example icaddr could be defined by:") (highlight scheme "(define icaddr (lambda (x) (icar (icdr (icdr x))))).") (p "Arbitrary compositions, up to four deep, are provided. There are twenty-eight of these procedures in all."))
(def (sig (procedure "(ilist-ref ilist i)" (id ilist-ref))) (p "Returns the ith element of ilist. (This is the same as the icar of (idrop ilist i).) It is an error if i >= n, where n is the length of ilist.") (highlight scheme "(ilist-ref (iq a b c d) 2) ;=> c"))
(def (sig (procedure "(ifirst ipair)" (id ifirst)) (procedure "(isecond ipair)" (id isecond)) (procedure "(ithird ipair)" (id ithird)) (procedure "(ifourth ipair)" (id ifourth)) (procedure "(ififth ipair)" (id ififth)) (procedure "(isixth ipair)" (id isixth)) (procedure "(iseventh ipair)" (id iseventh)) (procedure "(ieigth ipair)" (id ieigth)) (procedure "(ininth ipair)" (id ininth)) (procedure "(itenth ipair)" (id itenth))) (p "Synonyms for car, cadr, caddr, ...") (highlight scheme "(ithird '(a b c d e)) ;=> c") (p "<procedure>(icar+icdr ipair)<procedure>") (p "The fundamental ipair deconstructor:") (highlight scheme "(lambda (p) (values (icar p) (icdr p)))") (p "This can, of course, be implemented more efficiently by a compiler."))
(def (sig (procedure "(itake x i)" (id itake)) (procedure "(idrop x i)" (id idrop)) (procedure "(ilist-tail x i)" (id ilist-tail))) (p (tt "itake") " returns the first " (tt "i") " elements of ilist " (tt "x") ". " (tt "idrop") " returns all but the first " (tt "i") " elements of ilist " (tt "x") ". " (tt "ilist-tail") " is either the same procedure as " (tt "idrop") " or else a procedure with the same behavior.") (highlight scheme "(itake (iq a b c d e)  2) ;=> (a b)\n(idrop (iq a b c d e)  2) ;=> (c d e)") (p (tt "x") " may be any value — a proper or dotted ilist:") (highlight scheme "(itake (ipair 1 (ipair 2 (ipair 3 'd)))    ;=> (1 2)\n(idrop (ipair 1 (ipair 2 (ipair 3 'd))) 2) ;=> (3 . d)\n(itake (ipair 1 (ipair 2 (ipair 3 'd))) 3) ;=> (1 2 3)\n(idrop (ipair 1 (ipair 2 (ipair 3 'd))) 3) ;=> d") (p "For a legal " (tt "i") ", " (tt "itake") " and " (tt "idrop") " partition the ilist in a manner which can be inverted with " (tt "iappend") ":") (highlight scheme "(iappend (itake x i) (idrop x i)) = x") (p (tt "idrop") " is exactly equivalent to performing " (tt "i") " " (tt "icdr") " operations on " (tt "x") "; the returned value shares a common tail with " (tt "x") "."))
(def (sig (procedure "(itake-right dilist i)" (id itake-right)) (procedure "(idrop-right dilist i)" (id idrop-right))) (p (tt "itake-right") " returns the last " (tt "i") " elements of dilist. " (tt "idrop-right") " returns all but the last " (tt "i") " elements of dilist.") (highlight scheme "(itake-right (iq a b c d e) 2) ;=> (d e)\n(idrop-right (iq a b c d e) 2) ;=> (a b c)") (p "The returned ilist may share a common tail with the argument ilist.") (p (tt "dilist") " may be any ilist, either proper or dotted:") (highlight scheme "(itake-right (iq ipair 1 (ipair 2 (ipair 3 'd))) 2) ;=> (2 3 . d)\n(idrop-right (ipair 1 (ipair 2 (ipair 3 'd))) 2)    ;=> (1)\n(itake-right (ipair 1 (ipair 2 (ipair 3 'd))) 0)    ;=> d\n(idrop-right (ipair 1 (ipair 2 (ipair 3 'd))) 0)    ;=> (1 2 3)") (p "For a legal " (tt "i") ", " (tt "itake-right") " and " (tt "idrop-right") " partition the ilist in a manner which can be inverted with " (tt "iappend") ":") (highlight scheme "(iappend (itake dilist i) (idrop dilist i)) ;=> dilist") (p (tt "itake-right") "'s return value is guaranteed to share a common tail with " (tt "dilist") "."))
(def (sig (procedure "(isplit-at x i)" (id isplit-at))) (p (tt "isplit-at") " splits the ilist " (tt "x") " at index " (tt "i") ", returning an ilist of the first " (tt "i") " elements, and the remaining tail. It is equivalent to") (highlight scheme "(values (itake x i) (idrop x i))"))
(def (sig (procedure "(ilast ipair)" (id ilast)) (procedure "(last-ipair ipair)" (id last-ipair))) (p "Returns the last element of the non-empty, possibly dotted, ilist " (tt "ipair") ". " (tt "last-ipair") " returns the last ipair in the non-empty ilist " (tt "pair") ".") (highlight scheme "(ilast (iq a b c))      ;=> c\n(last-ipair (iq a b c)) ;=> (c)"))
(def (sig (procedure "(ilength ilist)" (id ilength))) (p "Returns the length of its argument. It is an error to pass a value to " (tt "ilength") " which is not a proper ilist (()-terminated).") (p "The length of a proper ilist is a non-negative integer n such that " (tt "icdr") " applied n times to the ilist produces the empty list."))
(def (sig (procedure "(iappend ilist1 ...)" (id iappend))) (p "Returns an ilist consisting of the elements of " (tt "ilist1") " followed by the elements of the other ilist parameters.") (highlight scheme "(iappend (iq x) (iq y))        ;=>  (x y)\n(iappend (iq a) (iq b c d))    ;=>  (a b c d)\n(iappend (iq a (b)) (iq (c)))  ;=>  (a (b) (c))") (p "The resulting ilist is always newly allocated, except that it shares structure with the final ilisti argument. This last argument may be any value at all; an improper ilist results if it is not a proper ilist. All other arguments must be proper ilists.") (highlight scheme "(iappend (iq a b) (ipair 'c 'd))  ;=>  (a b c . d)\n(iappend '() 'a)                  ;=>  a\n(iappend (iq x y))                ;=>  (x y)\n(iappend)                         ;=>  ()"))
(def (sig (procedure "(iconcatenate ilist-of-ilists)" (id iconcatenate))) (p "Appends the elements of its argument together. That is, " (tt "iconcatenate") " returns") (highlight scheme "(iapply iappend ilist-of-ilists)") (p "or, equivalently,") (highlight scheme "(ireduce-right iappend '() ilist-of-ilists)") (p "Note that some Scheme implementations do not support passing more than a certain number (e.g., 64) of arguments to an n-ary procedure. In these implementations, the " (tt "(iapply iappend ...)") " idiom would fail when applied to long lists, but " (tt "iconcatenate") " would continue to function properly.") (p "As with " (tt "iappend") ", the last element of the input list may be any value at all."))
(def (sig (procedure "(ireverse ilist)" (id ireverse))) (p "Returns a newly allocated ilist consisting of the elements of " (tt "ilist") " in reverse order.") (highlight scheme "(ireverse (iq a b c))             ;=>  (c b a)\n(ireverse (iq a (b c) d (e (f)))) ;=>  ((e (f)) d (b c) a)"))
(def (sig (procedure "(iappend-reverse rev-head tail)" (id iappend-reverse))) (p (tt "iappend-reverse") " returns " (tt "(iappend (ireverse rev-head) tail)") ". It is provided because it is a common operation — a common list-processing style calls for this exact operation to transfer values accumulated in reverse order onto the front of another ilist, and because the implementation is significantly more efficient than the simple composition it replaces. (But note that this pattern of iterative computation followed by a reverse can frequently be rewritten as a recursion, dispensing with the reverse and iappend-reverse steps, and shifting temporary, intermediate storage from the heap to the stack, which is typically a win for reasons of cache locality and eager storage reclamation.)"))
(def (sig (procedure "(izip ilist1 ilist2 ...)" (id izip))) (highlight scheme "(lambda ilists (iapply imap ilist ilists))") (p "If " (tt "izip") " is passed n ilists, it returns an ilist as long as the shortest of these ilists, each element of which is an n-element ilist comprised of the corresponding elements from the parameter ilists.") (highlight scheme "(izip (iq one two three)\n      (iq 1 2 3)\n      (iq odd even odd even odd even odd even))\n ;=> ((one 1 odd) (two 2 even) (three 3 odd))\n\n(izip (iq 1 2 3)) ;=> ((1) (2) (3))"))
(def (sig (procedure "(iunzip1 ilist)" (id iunzip1)) (procedure "(iunzip2 ilist)" (id iunzip2)) (procedure "(iunzip3 ilist)" (id iunzip3)) (procedure "(iunzip4 ilist)" (id iunzip4)) (procedure "(iunzip5 ilist)" (id iunzip5))) (p (tt "iunzip1") " takes an ilist of ilists, where every ilist must contain at least one element, and returns an ilist containing the initial element of each such ilist. That is, it returns " (tt "(imap icar ilists)") ".") (p (tt "unzip2") " takes an ilist of ilists, where every ilist must contain at least two elements, and returns two values: an ilist of the first elements, and an ilist of the second elements.") (p (tt "iunzip3") " does the same for the first three elements of the ilists, and so forth.") (highlight scheme "(iunzip2 (iq (1 one) (2 two) (3 three)))\n ;=> (1 2 3)\n ;=> (one two three)"))
(def (sig (procedure "(icount pred ilist1 ilist2 ...)" (id icount))) (p (tt "pred") " is a procedure taking as many arguments as there are ilists and returning a single value. It is applied element-wise to the elements of the ilists, and a count is tallied of the number of elements that produce a true value. This count is returned. " (tt "count") " is \"iterative\" in that it is guaranteed to apply " (tt "pred") " to the ilist elements in a left-to-right order. The counting stops when the shortest ilist expires.") (highlight scheme "(count even? (iq 3 1 4 1 5 9 2 5 6))            ;=> 3\n(count < (iq 1 2 4 8) (iq 2 4 6 8 10 12 14 16)) ;=> 3"))
(def (sig (procedure "(ifold konx knil ilist1 ilist2 ...)" (id ifold))) (p "The fundamental ilist iterator.") (p "First, consider the single ilist-parameter case. If ilist1 is (e1 e2 ... en), then this procedure returns") (highlight scheme "(kons en ... (kons e2 (kons e1 knil)) ... )") (p "That is, it obeys the (tail) recursion") (highlight scheme "(ifold kons knil lis) ;=> (ifold kons (kons (icar lis) knil) (icdr lis))\n(ifold kons knil '()) ;=> knil") (p "Examples:") (highlight scheme "(ifold + 0 lis)             ; Add up the elements of LIS.\n(ifold ipair '() lis)       ; Reverse LIS.\n(ifold ipair tail rev-head) ; See APPEND-REVERSE.\n\n;; How many symbols in LIS?\n(ifold (lambda (x count) (if (symbol? x) (+ count 1) count))\n      0\n      lis)\n\n;; Length of the longest string in LIS:\n(ifold (lambda (s max-len) (max max-len (string-length s)))\n      0\n      lis)") (p "If n ilist arguments are provided, then the " (tt "kons") " function must take n+1 parameters: one element from each ilist, and the \"seed\" or fold state, which is initially " (tt "knil") ". The fold operation terminates when the shortest ilist runs out of values:") (highlight scheme "(ifold ipair* '() (iq a b c) (iq 1 2 3 4 5)) ;=> (c 3 b 2 a 1)"))
(def (sig (procedure "(ifold-right kons knil ilist1 ilist2 ...)" (id ifold-right))) (p "The fundamental ilist recursion operator.") (p "First, consider the single ilist-parameter case. If ilist1 is (e1 e2 ... en), then this procedure returns") (highlight scheme "(kons e1 (kons e2 ... (kons en knil)))") (p "That is, it obeys the recursion") (highlight scheme "(ifold-right kons knil lis) ;=> (kons (icar lis) (ifold-right kons knil (icdr lis)))\n(ifold-right kons knil '()) ;=> knil") (p "Examples:") (highlight scheme "(ifold-right ipair '() lis)     ; Copy LIS.\n\n;; Filter the even numbers out of LIS.\n(ifold-right (lambda (x l) (if (even? x) (ipair x l) l)) '() lis))") (p "If n ilist arguments are provided, then the " (tt "kons") " procedure must take n+1 parameters: one element from each ilist, and the \"seed\" or fold state, which is initially " (tt "knil") ". The fold operation terminates when the shortest ilist runs out of values:") (highlight scheme "(ifold-right ipair* '() (iq a b c) (iq 1 2 3 4 5)) ;=> (a 1 b 2 c 3)"))
(def (sig (procedure "(ipair-fold kons knil ilist1 ilist2 ...)" (id ipair-fold))) (p "Analogous to fold, but " (tt "kons") " is applied to successive sub-ilists of the ilists, rather than successive elements — that is, " (tt "kons") " is applied to the ipairs making up the lists, giving this (tail) recursion:") (highlight scheme "(ipair-fold kons knil lis) ;=> (let ((tail (icdr lis)))\n                           ;     (ipair-fold kons (kons lis knil) tail))\n(ipair-fold kons knil '()) ;=> knil") (p "Example:") (highlight scheme "(ipair-fold ipair '() (iq a b c)) ;=> ((c) (b c) (a b c))"))
(def (sig (procedure "(ipair-fold-right kons knil ilist1 ilist2 ...)" (id ipair-fold-right))) (p "Holds the same relationship with {{ifold-right} that {ipair-fold} holds with {ifold}. Obeys the recursion") (highlight scheme "(ipair-fold-right kons knil lis) ;=> (kons lis (ipair-fold-right kons knil (icdr lis)))\n(ipair-fold-right kons knil '()) ;=> knil") (p "Example:") (highlight scheme "(ipair-fold-right ipair '() (iq a b c)) ;=> ((a b c) (b c) (c))"))
(def (sig (procedure "(ireduce f ridentity ilist)" (id ireduce))) (p (tt "ireduce") " is a variant of " (tt "ifold") ".") (p (tt "ridentity") " should be a \"right identity\" of the procedure " (tt "f") " — that is, for any value x acceptable to " (tt "f") ",") (highlight scheme "(f x ridentity) ;=> x") (p "ireduce has the following definition: If ilist is (), return ridentity; Otherwise, return " (tt "(ifold f (icar ilist) (icdr ilist))") ". In other words, we compute " (tt "(ifold f ridentity ilist)") ".") (p (b "Note") " that " (tt "ridentity") " is used only in the empty-list case. You typically use " (tt "ireduce") " when applying " (tt "f") " is expensive and you'd like to avoid the extra application incurred when " (tt "ifold") " applies " (tt "f") " to the head of " (tt "ilist") " and the " (tt "identity") " value, redundantly producing the same value passed in to " (tt "f") ". For example, if " (tt "f") " involves searching a file directory or performing a database query, this can be significant. In general, however, " (tt "ifold") " is useful in many contexts where " (tt "ireduce") " is not (consider the examples given in the " (tt "ifold") " definition -- only one of the five folds uses a function with a right identity. The other four may not be performed with " (tt "ireduce") ").") (highlight scheme ";; take the max of an ilist of non-negative integers.\n(ireduce max 0 nums) ; i.e., (iapply max 0 nums)"))
(def (sig (procedure "(ireduce-right f ridentity ilist)" (id ireduce-right))) (p (tt "ireduce-right") " is the " (tt "fold-right") " variant of " (tt "ireduce") ". It obeys the following definition:") (highlight scheme "(ireduce-right f ridentity '())            ;=> ridentity\n(ireduce-right f ridentity (iq e1))        ;=> (f e1 ridentity) ;=> e1\n(ireduce-right f ridentity (iq e1 e2 ...)) ;=> (f e1 (ireduce f ridentity (e2 ...)))") (p "...in other words, we compute " (tt "(ifold-right f ridentity ilist)") ".") (highlight scheme ";; Append a bunch of ilists together.\n;; I.e., (iapply iappend ilist-of-ilists)\n(ireduce-right iappend '() ilist-of-ilists)"))
(def (sig (procedure "(iunfold p f g seed [tail-gen])" (id iunfold))) (p (tt "iunfold") " is best described by its basic recursion:") (highlight scheme "(iunfold p f g seed) =\n    (if (p seed) (tail-gen seed)\n        (ipair (f seed)\n              (iunfold p f g (g seed))))") (dl (dt "p") (dd "Determines when to stop unfolding.") (dt "f") (dd "Maps each seed value to the corresponding ilist element.") (dt "g") (dd "Maps each seed value to next seed value.") (dt "seed") (dd "The \"state\" value for the unfold.") (dt "tail-gen") (dd "Creates the tail of the ilist; defaults to " (tt "(lambda (x) '())"))) (p "In other words, we use g to generate a sequence of seed values seed, (g seed), (g2 seed), (g3 seed), ...  These seed values are mapped to ilist elements by " (tt "f") ", producing the elements of the result ilist in a left-to-right order. " (tt "P") " says when to stop (i.e. when it returns true the procedure ends).") (p (tt "iunfold") " is the fundamental recursive ilist constructor, just as " (tt "ifold-right") " is the fundamental recursive ilist consumer. While " (tt "iunfold") " may seem a bit abstract to novice functional programmers, it can be used in a number of ways:") (highlight scheme ";; Ilist of squares: 1^2 ... 10^2\n(iunfold (lambda (x) (> x 10))\n        (lambda (x) (* x x))\n    (lambda (x) (+ x 1))\n    1)\n\n(iunfold null-ilist? icar icdr lis) ; Copy a proper ilist.\n\n;; Read current input port into an ilist of values.\n(iunfold eof-object? values (lambda (x) (read)) (read))\n\n;; Copy a possibly non-proper ilist:\n(iunfold not-ipair? icar icdr lis\n              values)\n\n;; Append HEAD onto TAIL:\n(iunfold null-ilist? icar icdr head\n              (lambda (x) tail))") (p "Interested functional programmers may enjoy noting that " (tt "ifold-right") " and " (tt "iunfold") " are in some sense inverses. That is, given operations " (tt "knull?") ", " (tt "kar") ", " (tt "kdr") ", " (tt "kons") ", and knil satisfying") (highlight scheme "(kons (kar x) (kdr x)) ;=> x ;AND\n(knull? knil)          ;=> #t") (p "then") (highlight scheme "(ifold-right kons knil (iunfold knull? kar kdr x)) ;=> x ;AND\n(iunfold knull? kar kdr (ifold-right kons knil x)) ;=> x") (p "This combinator sometimes is called an \"anamorphism;\" when an explicit tail-gen procedure is supplied, it is called an \"apomorphism.\""))
(def (sig (procedure "(iunfold-right p f g seed [tail])" (id iunfold-right))) (p (tt "iunfold-right") " constructs an ilist with the following loop:") (highlight scheme "(let lp ((seed seed) (lis tail))\n  (if (p seed) lis\n      (lp (g seed)\n          (ipair (f seed) lis))))") (dl (dt "p") (dd "Determines when to stop unfolding.") (dt "f") (dd "Maps each seed value to the corresponding ilist element.") (dt "g") (dd "Maps each seed value to next seed value.") (dt "seed") (dd "The \"state\" value for the unfold.") (dt "tail") (dd "ilist terminator; defaults to '().")) (p "In other words, we use g to generate a sequence of seed values seed, (g seed), (g2 seed), (g3 seed), ...  These seed values are mapped to ilist elements by " (tt "f") ", producing the elements of the result ilist in a right-to-left order. " (tt "P") " says when to stop.") (p (tt "iunfold-right") " is the fundamental iterative ilist constructor, just as " (tt "ifold") " is the fundamental iterative ilist consumer. While " (tt "iunfold-right") " may seem a bit abstract to novice functional programmers, it can be used in a number of ways:") (highlight scheme ";; Ilist of squares: 1^2 ... 10^2\n(iunfold-right zero?\n              (lambda (x) (* x x))\n              (lambda (x) (- x 1))\n              10)\n\n;; Reverse a proper ilist.\n(iunfold-right null-ilist? icar icdr lis)\n\n;; Read current input port into an ilist of values.\n(iunfold-right eof-object? values (lambda (x) (read)) (read))\n\n;; (iappend-reverse rev-head tail)\n(iunfold-right null-ilist? icar icdr rev-head tail)"))
(def (sig (procedure "(imap proc ilist1 ilist2 ...)" (id imap))) (p (tt "proc") " is a procedure taking as many arguments as there are ilist arguments and returning a single value. " (tt "imap") " applies " (tt "proc") " element-wise to the elements of the ilists and returns an ilist of the results, in order. The dynamic order in which " (tt "proc") " is applied to the elements of the ilists is unspecified.") (highlight scheme "(imap icadr (iq (a b) (d e) (g h))) ;=>  (b e h)\n\n(imap (lambda (n) (expt n n))\n      (iq 1 2 3 4 5))\n ;=>  (1 4 27 256 3125)\n\n(imap + (iq 1 2 3) (iq 4 5 6)) ;=>  (5 7 9)\n\n(let ((count 0))\n  (imap (lambda (ignored)\n         (set! count (+ count 1))\n         count)\n       (iq a b))) ;=>  (1 2) or (2 1)"))
(def (sig (procedure "(ifor-each proc ilist1 ilist2 ...)" (id ifor-each))) (p "The arguments to " (tt "ifor-each") " are like the arguments to " (tt "imap") ", but " (tt "ifor-each") " calls " (tt "proc") " for its side effects rather than for its values. Unlike " (tt "imap") ", " (tt "ifor-each") " is guaranteed to call " (tt "proc") " on the elements of the ilists in order from the first element(s) to the last, and the value returned by " (tt "ifor-each") " is unspecified.") (highlight scheme "(let ((v (make-vector 5)))\n  (ifor-each (lambda (i)\n              (vector-set! v i (* i i)))\n            (iq 0 1 2 3 4))\n  v)  ;=>  #(0 1 4 9 16)"))
(def (sig (procedure "(iappend-map f ilist1 ilist2 ...)" (id iappend-map))) (p "Equivalent to " (tt "(iapply iappend (imap f ilist1 ilist2 ...))") " and " (tt "(iapply iappend (imap f ilist1 ilist2 ...))") ". Map " (tt "f") " over the elements of the ilists, just as in the " (tt "imap") " function. However, the results of the applications are appended together (using " (tt "iappend") ") to make the final result.") (p "The dynamic order in which the various applications of " (tt "f") " are made is not specified.") (p "Example:") (highlight scheme "(iappend-map (lambda (x) (ilist x (- x))) (iq 1 3 8)) ;=> (1 -1 3 -3 8 -8)"))
(def (sig (procedure "(imap-in-order f ilist1 ilist2 ...)" (id imap-in-order))) (p "A variant of the " (tt "imap") " procedure that guarantees to apply " (tt "f") " across the elements of the " (tt "ilisti") " arguments in a left-to-right order. This is useful for mapping procedures that both have side effects and return useful values."))
(def (sig (procedure "(ipair-for-each f ilist1 ilist2 ...)" (id ipair-for-each))) (p "Like " (tt "ifor-each") ", but " (tt "f") " is applied to successive sub-ilists of the argument ilists. That is, " (tt "f") " is applied to the cells of the ilists, rather than the ilists' elements. These applications occur in left-to-right order.") (highlight scheme "(ipair-for-each (lambda (ipair) (display ipair) (newline)) (iq a b c))\n ;=> (a b c)\n ;=> (b c)\n ;=> (c)"))
(def (sig (procedure "(ifilter-map f ilist1 ilist2 ...)" (id ifilter-map))) (p "Like " (tt "imap") ", but only true values are saved.") (highlight scheme "(ifilter-map (lambda (x) (and (number? x) (* x x))) (iq a 1 b 3 c 7))\n ;=> (1 9 49)") (p "The dynamic order in which the various applications of " (tt "f") " are made is not specified."))
(def (sig (procedure "(ifilter pred ilist)" (id ifilter))) (p "Return all the elements of " (tt "ilist") " that satisfy predicate " (tt "pred") ". The ilist is not disordered — elements that appear in the result ilist occur in the same order as they occur in the argument " (tt "ilist") ". The returned ilist may share a common tail with the argument " (tt "ilist") ". The dynamic order in which the various applications of " (tt "pred") " are made is not specified.") (highlight scheme "(ifilter even? (iq 0 7 8 8 43 -4)) ;=> (0 8 8 -4)"))
(def (sig (procedure "(ipartition pred ilist)" (id ipartition))) (p "Partitions the elements of " (tt "ilist") " with predicate " (tt "pred") ", and returns two values: the ilist of in-elements and the ilist of out-elements. The ilist is not disordered — elements occur in the result ilists in the same order as they occur in the argument " (tt "ilist") ". The dynamic order in which the various applications of pred are made is not specified. One of the returned ilists may share a common tail with the argument " (tt "ilist") ".") (highlight scheme "(ipartition symbol? (iq one 2 3 four five 6))\n ;=> (one four five)\n ;=> (2 3 6)"))
(def (sig (procedure "(iremove pred ilist)" (id iremove))) (p "Returns " (tt "ilist") " without the elements that satisfy predicate " (tt "pred") ":") (highlight scheme "(lambda (pred ilist) (ifilter (lambda (x) (not (pred x))) ilist))") (p "The ilist is not disordered — elements that appear in the result ilist occur in the same order as they occur in the argument " (tt "ilist") ". The returned ilist may share a common tail with the argument " (tt "ilist") ". The dynamic order in which the various applications of " (tt "pred") " are made is not specified.") (highlight scheme "(iremove even? (iq 0 7 8 8 43 -4)) ;=> (7 43)"))
(def (sig (procedure "(ifind pred ilist)" (id ifind))) (p "Return the first element of " (tt "ilist") " that satisfies predicate " (tt "pred") "; false if no element does.") (highlight scheme "(ifind even? (iq 3 1 4 1 5 9)) ;=> 4") (p "Note that " (tt "ifind") " has an ambiguity in its lookup semantics — if " (tt "ifind") " returns " (tt "#f") ", you cannot tell (in general) if it found a " (tt "#f") " element that satisfied pred, or if it did not find any element at all. In many situations, this ambiguity cannot arise — either the ilist being searched is known not to contain any " (tt "#f") " elements, or the ilist is guaranteed to have an element satisfying " (tt "pred") ". However, in cases where this ambiguity can arise, you should use " (tt "ifind-tail") " instead of " (tt "ifind") " -- " (tt "ifind-tail") " has no such ambiguity:") (highlight scheme "(cond ((ifind-tail pred lis) => (lambda (ipair) ...)) ; Handle (icar ipair)\n      (else ...)) ; Search failed."))
(def (sig (procedure "(ifind-tail pred ilist)" (id ifind-tail))) (p "Return the first ipair of " (tt "ilist") " whose " (tt "icar") " satisfies " (tt "pred") ". If no ipair does, return false.") (p (tt "ifind-tail") " can be viewed as a general-predicate variant of the " (tt "imember") " function.") (p "Examples:") (highlight scheme "(ifind-tail even? (iq 3 1 37 -8 -5 0 0)) ;=> (-8 -5 0 0)\n(ifind-tail even? (iq 3 1 37 -5))        ;=> #f\n\n;; IMEMBER X LIS:\n(ifind-tail (lambda (elt) (equal? x elt)) lis)") (p (tt "ifind-tail") " is essentially " (tt "idrop-while") ", where the sense of the predicate is inverted: " (tt "ifind-tail") " searches until it finds an element satisfying the predicate; " (tt "idrop-while") " searches until it finds an element that doesn't satisfy the predicate."))
(def (sig (procedure "(itake-while pred ilist)" (id itake-while))) (p "Returns the longest initial prefix of " (tt "ilist") " whose elements all satisfy the predicate " (tt "pred") ".") (highlight scheme "(itake-while even? (iq 2 18 3 10 22 9)) ;=> (2 18)"))
(def (sig (procedure "(idrop-while pred ilist)" (id idrop-while))) (p (tt "idrops") " the longest initial prefix of " (tt "ilist") " whose elements all satisfy the predicate " (tt "pred") ", and returns the rest of the ilist.") (highlight scheme "(idrop-while even? (iq 2 18 3 10 22 9)) ;=> (3 10 22 9)"))
(def (sig (procedure "(ispan pred ilist)" (id ispan)) (procedure "(ibreak pred ilist)" (id ibreak))) (p (tt "ispan") " splits the " (tt "ilist") " into the longest initial prefix whose elements all satisfy " (tt "pred") ", and the remaining tail. " (tt "ibreak") " inverts the sense of the predicate: the tail commences with the first element of the input " (tt "ilist") " that satisfies the predicate.") (p "In other words: " (tt "ispan") " finds the initial span of elements satisfying " (tt "pred") ", and " (tt "ibreak") " breaks the " (tt "ilist") " at the first element satisfying " (tt "pred") ".") (p (tt "ispan") " is equivalent to") (highlight scheme "(values (itake-while pred ilist)\n        (idrop-while pred ilist))\n\n(ispan even? (iq 2 18 3 10 22 9)) =>\n  (2 18)\n  (3 10 22 9)\n\n(ibreak even? (iq 3 1 4 1 5 9)) =>\n  (3 1)\n  (4 1 5 9)"))
(def (sig (procedure "(iany pred ilist1 ilist2 ...)" (id iany))) (p "Applies the predicate across the ilists, returning true if the predicate returns true on any application.") (p "If there are n ilist arguments " (tt "ilist1") " ... " (tt "ilistn") ", then " (tt "pred") " must be a procedure taking n arguments and returning a boolean result.") (p (tt "iany") " applies " (tt "pred") " to the first elements of the " (tt "ilisti") " parameters. If this application returns a true value, " (tt "iany") " immediately returns that value.  Otherwise, it iterates, applying " (tt "pred") " to the second elements of the " (tt "ilisti") " parameters, then the third, and so forth. The iteration stops when a true value is produced or one of the ilists runs out of values; in the latter case, " (tt "iany") " returns " (tt "#f") ". The application of " (tt "pred") " to the last element of the ilists is a tail call.") (p "Note the difference between " (tt "ifind") " and " (tt "iany") " — " (tt "ifind") " returns the element that satisfied the predicate; " (tt "iany") " returns the true value that the predicate produced.") (p "Like " (tt "ievery") ", " (tt "iany") "'s name does not end with a question mark — this is to indicate that it does not return a simple boolean (" (tt "#t") " or " (tt "#f") "), but a general value.") (highlight scheme "(iany integer? (iq a 3 b 2.7))   ;=> #t\n(iany integer? (iq a 3.1 b 2.7)) ;=> #f\n(iany < (iq 3 1 4 1 5)\n        (iq 2 7 1 8 2))          ;=> #t"))
(def (sig (procedure "(ievery pred ilist1 ilist2 ...)" (id ievery))) (p "Applies the predicate across the ilists, returning true if the predicate returns true on every application.") (p "If there are n ilist arguments " (tt "ilist1") " ... " (tt "ilistn") ", then " (tt "pred") " must be a procedure taking n arguments and returning a boolean result.") (p (tt "ievery") " applies pred to the first elements of the " (tt "ilisti") " parameters. If this application returns false, " (tt "ievery") " immediately returns " (tt "false") ". Otherwise, it iterates, applying " (tt "pred") " to the second elements of the " (tt "ilisti") " parameters, then the third, and so forth. The iteration stops when a false value is produced or one of the ilists runs out of values. In the latter case, " (tt "ievery") " returns the true value produced by its final application of " (tt "pred") ". The application of " (tt "pred") " to the last element of the ilists is a tail call.") (p "If one of the " (tt "ilisti") " has no elements, " (tt "ievery") " simply returns " (tt "#t") ".") (p "Like " (tt "iany") ", " (tt "ievery") "'s name does not end with a question mark — this is to indicate that it does not return a simple boolean (" (tt "#t") " or " (tt "#f") "), but a general value."))
(def (sig (procedure "(ilist-index pred ilist1 ilist2 ...)" (id ilist-index))) (p "Return the index of the leftmost element that satisfies " (tt "pred") ".") (p "If there are n ilist arguments " (tt "ilist1") " ... " (tt "ilistn") ", then pred must be a function taking n arguments and returning a boolean result.") (p (tt "ilist-index") " applies " (tt "pred") " to the first elements of the " (tt "ilisti") " parameters. If this application returns true, " (tt "ilist-index") " immediately returns zero. Otherwise, it iterates, applying " (tt "pred") " to the second elements of the " (tt "ilisti") " parameters, then the third, and so forth. When it finds a tuple of ilist elements that cause " (tt "pred") " to return true, it stops and returns the zero-based index of that position in the ilists.") (p "The iteration stops when one of the ilists runs out of values; in this case, " (tt "ilist-index") " returns " (tt "#f") ".") (highlight scheme "(ilist-index even? (iq 3 1 4 1 5 9))                  ;=> 2\n(ilist-index < (iq 3 1 4 1 5 9 2 5 6) (iq 2 7 1 8 2)) ;=> 1\n(ilist-index = (iq 3 1 4 1 5 9 2 5 6) (iq 2 7 1 8 2)) ;=> #f"))
(def (sig (procedure "(imember x ilist [=])" (id imember)) (procedure "(imemq x ilist)" (id imemq)) (procedure "(imemv x ilist)" (id imemv))) (p "These procedures return the first sub-ilist of " (tt "ilist") " whose " (tt "icar") " is " (tt "x") ", where the sub-ilists of " (tt "ilist") " are the non-empty ilists returned by " (tt "(idrop ilist i)") " for i less than the length of ilist. If " (tt "x") " does not occur in " (tt "ilist") ", then " (tt "#f") " is returned. " (tt "imemq") " uses " (tt "eq?") " to compare " (tt "x") " with the elements of " (tt "ilist") ", while " (tt "imemv") " uses " (tt "eqv?") ", and " (tt "imember") " uses " (tt "equal?") ".") (highlight scheme "(imemq 'a (iq a b c))           ;=>  (a b c)\n(imemq 'b (iq a b c))           ;=>  (b c)\n(imemq 'a (iq b c d))           ;=>  #f\n(imemq (list 'a)\n       (ilist 'b '(a) 'c))      ;=>  #f\n(imember (list 'a)\n         (ilist 'b '(a) 'c)))   ;=>  ((a) c)\n(imemq 101 (iq 100 101 102))    ;=>  *unspecified*\n(imemv 101 (iq 100 101 102))    ;=>  (101 102)") (p "The comparison procedure is used to compare the elements ei of ilist to the key " (tt "x") " in this way:") (highlight scheme "(= x ei) ; ilist is (E1 ... En)") (p "That is, the first argument is always x, and the second argument is one of the ilist elements. Thus one can reliably find the first element of ilist that is greater than five with (imember 5 ilist <)") (p "Note that fully general ilist searching may be performed with the ifind-tail and ifind procedures, e.g.") (highlight scheme "(ifind-tail even? ilist) ; Find the first elt with an even key."))
(def (sig (procedure "(idelete x ilist [=])" (id idelete))) (p (tt "idelete") " uses the comparison procedure " (tt "=") ", which defaults to " (tt "equal?") ", to find all elements of " (tt "ilist") " that are equal to " (tt "x") ", and deletes them from " (tt "ilist") ". The dynamic order in which the various applications of {{}}=}} are made is not specified.") (p "The ilist is not disordered — elements that appear in the result ilist occur in the same order as they occur in the argument " (tt "ilist") ". The result may share a common tail with the argument " (tt "ilist") ".") (p "Note that fully general element deletion can be performed with the " (tt "iremove") " procedures, e.g.:") (highlight scheme ";; idelete all the even elements from LIS:\n(iremove even? lis)") (p "The comparison procedure is used in this way: " (tt "(= x ei)") ". That is, " (tt "x") " is always the first argument, and an " (tt "ilist") " element is always the second argument. The comparison procedure will be used to compare each element of " (tt "ilist") " exactly once; the order in which it is applied to the various " (tt "ei") " is not specified.  Thus, one can reliably remove all the numbers greater than five from an ilist with " (tt "(idelete 5 ilist <)")))
(def (sig (procedure "(idelete-duplicates ilist [=])" (id idelete-duplicates))) (p (tt "idelete-duplicates") " removes duplicate elements from the " (tt "ilist") " argument. If there are multiple equal elements in the argument " (tt "ilist") ", the result ilist only contains the first or leftmost of these elements in the result. The order of these surviving elements is the same as in the original " (tt "ilist") " -- " (tt "idelete-duplicates") " does not disorder the ilist (hence it is useful for \"cleaning up\" immutable association lists).") (p "The " (tt "=") " parameter is used to compare the elements of the " (tt "ilist") "; it defaults to " (tt "equal?") ". If " (tt "x") " comes before " (tt "y") " in ilist, then the comparison is performed " (tt "(= x y)") ".  The comparison procedure will be used to compare each pair of elements in " (tt "ilist") " no more than once; the order in which it is applied to the various pairs is not specified.") (p "Implementations of " (tt "idelete-duplicates") " are allowed to share common tails between argument and result ilists -- for example, if the " (tt "ilist") " argument contains only unique elements, it may simply return exactly this ilist.") (p "Be aware that, in general, " (tt "idelete-duplicates") " runs in time O(n^2) for n-element ilists. Uniquifying long ilists can be accomplished in O(n lg n) time by sorting the " (tt "ilist") " to bring equal elements together, then using a linear-time algorithm to remove equal elements. Alternatively, one can use algorithms based on element-marking, with linear-time results.") (highlight scheme "(idelete-duplicates (iq a b a c a b c z)) ;=> (a b c z)\n\n;; Clean up an ialist:\n(idelete-duplicates (iq (a . 3) (b . 7) (a . 9) (c . 1))\n                   (lambda (x y) (eq? (icar x) (icar y))))\n    ;=> ((a . 3) (b . 7) (c . 1))"))
(def (sig (procedure "(iassoc key ialist [=])" (id iassoc)) (procedure "(iassq key ialist)" (id iassq)) (procedure "(iassv key ialist)" (id iassv))) (p (tt "ialist") " must be an immutable association list — an ilist of ipairs. These procedures find the first ipair in ialist whose icar field is " (tt "key") ", and returns that ipair. If no ipair in ialist has key as its " (tt "icar") ", then " (tt "#f") " is returned.  " (tt "iassq") " uses " (tt "eq?") " to compare key with the " (tt "icar") " fields of the ipairs in " (tt "ialist") ", while " (tt "iassv") " uses " (tt "eqv?") " and " (tt "iassoc") " uses " (tt "equal?") ".") (highlight scheme "(define e (iq (a 1) (b 2) (c 3)))\n(iassq 'a e)                               ;=>  (a 1)\n(iassq 'b e)                               ;=>  (b 2)\n(iassq 'd e)                               ;=>  #f\n(iassq (ilist 'a) (iq ((a)) ((b)) ((c))))  ;=>  #f\n(iassoc '(a) (ilist '((a)) '((b)) '((c)))) ;=>  ((a))\n(iassq 5 (iq (2 3) (5 7) (11 13)))         ;=>  *unspecified*\n(iassv 5 (iq (2 3) (5 7) (11 13)))         ;=>  (5 7)") (p "The comparison procedure is used to compare the elements " (tt "ei") " of ilist to the " (tt "key") " parameter in this way:") (highlight scheme "(= key (icar ei)) ; ilist is (E1 ... En)") (p "That is, the first argument is always " (tt "key") ", and the second argument is one of the ilist elements. Thus one can reliably find the first entry of " (tt "ialist") " whose " (tt "key") " is greater than five with " (tt "(iassoc 5 ialist <)") ".") (p "Note that fully general " (tt "ialist") " searching may be performed with the " (tt "ifind-tail") " and " (tt "ifind") " procedures, e.g.") (highlight scheme ";; Look up the first association in ialist with an even key:\n(ifind (lambda (a) (even? (icar a))) ialist)"))
(def (sig (procedure "(ialist-cons key datum ialist)" (id ialist-cons))) (highlight scheme "(lambda (key datum ialist) (ipair (ipair key datum) ialist))") (p "Construct a new ialist entry mapping key -> datum onto ialist."))
(def (sig (procedure "(ialist-delete key ialist [=])" (id ialist-delete))) (p (tt "ialist-delete") " deletes all associations from " (tt "ialist") " with the given key, using key-comparison procedure " (tt "=") ", which defaults to " (tt "equal?") ". The dynamic order in which the various applications of " (tt "=") " are made is not specified.") (p "Return values may share common tails with the " (tt "ialist") " argument. The " (tt "ialist") " is not disordered -- elements that appear in the result ialist occur in the same order as they occur in the argument " (tt "ialist") ".") (p "The comparison procedure is used to compare the element keys " (tt "ki") " of " (tt "ialist") "'s entries to the key parameter in this way: " (tt "(= key ki)") ". Thus, one can reliably remove all entries of " (tt "ialist") " whose key is greater than five with " (tt "(ialist-delete 5 ialist <)")))
(def (sig (procedure "(replace-icar ipair object)" (id replace-icar))) (pre "This procedure returns an ipair with object in the icar field and the icdr of") (p (tt "ipair") " in the icdr field."))
(def (sig (procedure "(replace-icdr ipair object)" (id replace-icdr))) (p "This procedure returns an ipair with object in the icdr field and the icar of " (tt "ipair") " in the icar field."))
(def (sig (procedure "(pair->ipair pair)" (id pair->ipair)) (procedure "(ipair->pair ipair)" (id ipair->pair))) (p "These procedures, which are inverses, return an ipair and a pair respectively that have the same (i)car and (i)cdr fields as the argument."))
(def (sig (procedure "(list->ilist flist)" (id list->ilist)) (procedure "(ilist->list dlist)" (id ilist->list))) (p "These procedures return an ilist and a list respectively that have the same elements as the argument. The tails of dotted (i)lists are preserved in the result, which makes the procedures not inverses when the tail of a dotted ilist is a list or vice versa. The empty list is converted to itself.") (p "It is an error to apply " (tt "list->ilist") " to a circular list."))
(def (sig (procedure "(tree->itree obj)" (id tree->itree)) (procedure "(itree->tree obj)" (id itree->tree))) (p "These procedures walk a tree of pairs or ipairs respectively and make a deep copy of it, returning an isomorphic tree containing ipairs or pairs respectively. The result may share structure with the argument. If the argument is not of the expected type, it is returned.") (p "These procedures are not inverses in the general case. For example, a pair of ipairs would be converted by " (tt "tree->itree") " to an ipair of ipairs, which if converted by " (tt "itree->tree") " would produce a pair of pairs."))
(def (sig (procedure "(gtree->itree obj)" (id gtree->itree)) (procedure "(itree->gtree obj)" (id itree->gtree))) (p "These procedures walk a generalized tree consisting of pairs, ipairs, or a combination of both, and make a deep copy of it, returning an isomorphic tree containing only ipairs or pairs respectively. The result may share structure with the argument. If the argument is neither a pair nor an ipair, it is returned."))
(def (sig (procedure "(iapply procedure object ... ilist)" (id iapply))) (p "The iapply procedure is an analogue of apply whose last argument is an ilist rather than a list. It is equivalent to " (tt "(apply procedure object ... (ilist->list ilist))") ", but may be implemented more efficiently."))
