(index ("generator->lseq" 0) ("lseq?" 577) ("lseq=?" 940) ("lseq-car" 1716) ("lseq-first" 1716) ("lseq-cdr" 2043) ("lseq-rest" 2043) ("lseq-ref" 3017) ("lseq-take" 3321) ("lseq-drop" 3321) ("lseq-realize" 3834) ("lseq->generator" 4309) ("lseq-length" 4520) ("lseq-append" 4821) ("lseq-zip" 4974) ("lseq-map" 5568) ("lseq-for-each" 6426) ("lseq-filter" 7274) ("lseq-remove" 7274) ("lseq-find" 7976) ("lseq-find-tail" 8471) ("lseq-take-while" 9154) ("lseq-drop-while" 9428) ("lseq-any" 10036) ("lseq-every" 11373) ("lseq-index" 12325) ("lseq-member" 13180) ("lseq-memq" 13180) ("lseq-memv" 13180))
(def (sig (procedure "(generator->lseq generator)" (id generator->lseq))) (p "Returns an lseq whose elements are the values generated by " (tt "generator") ". The exact behavior is as follows:") (ul (li (tt "generator") " is invoked with no arguments to produce an object " (tt "obj") ".") (li "If " (tt "obj") " is an end-of-file object, the empty list is returned.") (li "Otherwise, a newly allocated pair whose car is " (tt "obj") " and whose cdr is " (tt "generator") " is returned.")) (highlight scheme "(generator->lseq (make-iota-generator +inf.0 1)) ;=> (1 2 3 ...)"))
(def (sig (procedure "(lseq? x)" (id lseq?))) (p "Returns " (tt "#t") " if " (tt "x") " is an lseq. This procedure may also return " (tt "#t") " if x is an improper list whose last cdr is a procedure that requires arguments, since there is no portable way to examine a procedure to determine how many arguments it requires. Otherwise it returns " (tt "#f") "."))
(def (sig (procedure "(lseq=? elt=? lseq1 lseq2)" (id lseq=?))) (p "Determines lseq equality, given an element-equality procedure. Two lseqs are equal if they are of the same length, and their corresponding elements are equal, as determined by " (tt "elt=?") ". When " (tt "elt=?") " is called, its first argument is always from " (tt "lseq1") " and its second argument is from " (tt "lseq2") ".") (p "The dynamic order in which the " (tt "elt=?") " procedure is applied to pairs of elements is not specified.") (p "The " (tt "elt=?") " procedure must be consistent with " (tt "eq?") ". This implies that two lseqs which are " (tt "eq?") " are always " (tt "lseq=?") ", as well; implementations may exploit this fact to \"short-cut\" the element-by-element equality tests."))
(def (sig (procedure "(lseq-car lseq)" (id lseq-car)) (procedure "(lseq-first lseq)" (id lseq-first))) (p "These procedures are synonymous. They return the first element of " (tt "lseq") ". They are included for completeness, as they are the same as " (tt "car") ". It is an error to apply them to an empty " (tt "lseq") "."))
(def (sig (procedure "(lseq-cdr lseq)" (id lseq-cdr)) (procedure "(lseq-rest lseq)" (id lseq-rest))) (p "These procedures are synonymous. They return an lseq with the contents of " (tt "lseq") " except for the first element. The exact behavior is as follows:") (ul (li "If lseq is a pair whose cdr is a procedure, then the procedure is invoked with no arguments to produce an object " (tt "obj") "." (ul (li "If " (tt "obj") " is an end-of-file object, then the cdr of lseq is set to the empty list, which is returned.") (li "If " (tt "obj") " is any other object, then a new pair is allocated whose car is " (tt "obj") " and whose cdr is the cdr of lseq (i.e. the procedure). The cdr of lseq is set to the newly allocated pair, which is returned."))) (li "If lseq is a pair whose cdr is not a procedure, then the cdr is returned.") (li "If lseq is not a pair, it is an error.")) (p "Implementations that inline cdr are advised to inline " (tt "lseq-cdr") " if possible."))
(def (sig (procedure "(lseq-ref lseq i)" (id lseq-ref))) (p "Returns the ith element of " (tt "lseq") ". (This is the same as " (tt "(lseq-first (lseq-drop lseq i))") "). It is an error if i >= n, where " (tt "n") " is the length of " (tt "lseq") ".") (highlight scheme "(lseq-ref '(a b c d) 2) ;=> c"))
(def (sig (procedure "(lseq-take lseq i)" (id lseq-take)) (procedure "(lseq-drop lseq i)" (id lseq-drop))) (p (tt "lseq-take") " lazily returns the first " (tt "i") " elements of " (tt "lseq") ". " (tt "lseq-drop") " returns all but the first " (tt "i") " elements of " (tt "lseq") ".") (highlight scheme "(lseq-take '(a b c d e)  2) ;=> (a b)\n(lseq-drop '(a b c d e)  2) ;=> (c d e)") (p (tt "lseq-drop") " is exactly equivalent to performing " (tt "i") " " (tt "lseq-rest") " operations on " (tt "lseq") "."))
(def (sig (procedure "(lseq-realize lseq)" (id lseq-realize))) (p "Repeatedly applies " (tt "lseq-cdr") " to " (tt "lseq") " until its generator (if there is one) has been exhausted, and returns " (tt "lseq") ", which is now guaranteed to be a proper list. This procedure can be called on an arbitrary lseq before passing it to a procedure which only accepts lists. However, if the generator never returns an end-of-file object, " (tt "lseq-realize") " will never return."))
(def (sig (procedure "(lseq->generator lseq)" (id lseq->generator))) (p "Returns a generator which when invoked will return all the elements of " (tt "lseq") ", including any that have not yet been realized."))
(def (sig (procedure "(lseq-length lseq)" (id lseq-length))) (p "Returns the length of its argument, which is the non-negative integer n such that " (tt "lseq-rest") " applied n times to the " (tt "lseq") " produces an empty lseq. " (tt "lseq") " must be finite, or this procedure will not return."))
(def (sig (procedure "(lseq-append lseq ...)" (id lseq-append))) (p "Returns an lseq that lazily contains all the elements of all the lseqs in order."))
(def (sig (procedure "(lseq-zip lseq1 lseq2 ...)" (id lseq-zip))) (p "If " (tt "lseq-zip") " is passed n lseqs, it lazily returns an lseq each element of which is an n-element list comprised of the corresponding elements from the lseqs. If any of the lseqs are finite in length, the result is as long as the shortest lseq.") (highlight scheme "(lseq-zip '(one two three)\n          (generator->lseq (make-iota-generator +inf.0 1 1))\n          (generator->lseq (make-repeating-generator) '(odd even))))\n ;=> ((one 1 odd) (two 2 even) (three 3 odd))\n\n(lseq-zip '(1 2 3)) ;=> ((1) (2) (3))"))
(def (sig (procedure "(lseq-map proc lseq1 lseq2 ...)" (id lseq-map))) (p "The " (tt "lseq-map") " procedure lazily applies " (tt "proc") " element-wise to the corresponding elements of the lseqs, where " (tt "proc") " is a procedure taking as many arguments as there are lseqs and returning a single value, and returns an lseq of the results in order. The dynamic order in which " (tt "proc") " is applied to the elements of the lseqs is unspecified.") (highlight scheme "(lseq-map\n (lambda (x) (lseq-car (lseq-cdr x)))\n '((a b) (d e) (g h)))\n ;=>  (b e h)\n\n(lseq-map (lambda (n) (expt n n))\n (make-iota-generator +inf.0 1 1)\n ;=> (1 4 27 256 3125 ...)\n\n (lseq-map + '(1 2 3) '(4 5 6)) =>  (5 7 9)\n\n (let ((count 0))\n  (lseq-map (lambda (ignored)\n             (set! count (+ count 1))\n             count)\n   '(a b)))\n ;=>  (1 2) or (2 1)"))
(def (sig (procedure "(lseq-for-each proc lseq1 lseq2 ...)" (id lseq-for-each))) (p "The arguments to " (tt "lseq-for-each") " are like the arguments to " (tt "lseq-map") ", but " (tt "lseq-for-each") " calls " (tt "proc") " for its side effects rather than for its values.  Unlike " (tt "lseq-map") ", " (tt "lseq-for-each") " is guaranteed to call " (tt "proc") " on the elements of the lseqs in order from the first element(s) to the last, and the value returned by " (tt "lseq-for-each") " is unspecified. If none of the lseqs are finite, lseq-for-each never returns.") (highlight scheme "(let ((v (make-vector 5)))\n  (lseq-for-each (let ((count 0))\n                   (lambda (i)\n                     (vector-set! v count (* i i))\n                     (set! count (+ count 1))))\n                 '(0 1 2 3 4))\n  v)\n ;=> (#0 1 2 3 4)"))
(def (sig (procedure "(lseq-filter pred lseq)" (id lseq-filter)) (procedure "(lseq-remove pred lseq)" (id lseq-remove))) (p "The procedure " (tt "lseq-filter") " lazily returns an lseq that contains only the elements of " (tt "lseq") " that satisfy " (tt "pred") ".") (p "The procedure " (tt "lseq-remove") " is the same as " (tt "lseq-filter") ", except that it returns elements that do not satisfy " (tt "pred") ". These procedures are guaranteed to call " (tt "pred") " on the elements of the lseqs in sequence order.") (highlight scheme "(lseq-filter odd? (generator->lseq (make-range-generator 1 5)))\n ;=>  (1 3)\n\n(lseq-remove odd? (generator->lseq (make-range-generator 1 5)))\n ;=>  (2 4)"))
(def (sig (procedure "(lseq-find pred lseq)" (id lseq-find))) (p "Return the first element of " (tt "lseq") " that satisfies predicate " (tt "pred") ", or " (tt "#f") " if no element does. It cannot reliably be applied to lseqs that include " (tt "#f") " as an element; use " (tt "lseq-find-tail") " instead. The predicate is guaranteed to be evaluated on the elements of lseq in sequence order, and only as often as necessary.") (highlight scheme "(lseq-find even? '(3 1 4 1 5 9 2 6)) ;=> 4"))
(def (sig (procedure "(lseq-find-tail pred lseq)" (id lseq-find-tail))) (p "Returns the longest tail of " (tt "lseq") " whose first element satisfies " (tt "pred") ", or " (tt "#f") " if no element does. The predicate is guaranteed to be evaluated on the elements of lseq in sequence order, and only as often as necessary.") (p (tt "lseq-find-tail") " can be viewed as a general-predicate variant of the " (tt "lseq-member") " function.") (p "Examples:") (highlight scheme "(lseq-find-tail even? '(3 1 37 -8 -5 0 0)) ;=> (-8 -5 0 0)\n(lseq-find-tail even? '(3 1 37 -5))        ;=> #f\n\n;; equivalent to (lseq-member elt lseq)\n(lseq-find-tail (lambda (elt) (equal? x elt)) lseq)"))
(def (sig (procedure "(lseq-take-while pred lseq)" (id lseq-take-while))) (p "Lazily returns the longest initial prefix of " (tt "lseq") " whose elements all satisfy the predicate " (tt "pred") ".") (highlight scheme "(lseq-take-while even? '(2 18 3 10 22 9)) ;=> (2 18)"))
(def (sig (procedure "(lseq-drop-while pred lseq)" (id lseq-drop-while))) (p "Drops the longest initial prefix of " (tt "lseq") " whose elements all satisfy the predicate pred, and returns the rest of the lseq.") (highlight scheme "(lseq-drop-while even? '(2 18 3 10 22 9)) ;=> (3 10 22 9)") (p "Note that " (tt "lseq-drop-while") " is essentially " (tt "lseq-find-tail") " where the sense of the predicate is inverted: " (tt "lseq-find-tail") " searches until it finds an element satisfying the predicate; " (tt "lseq-drop-while") " searches until it finds an element that doesn't satisfy the predicate."))
(def (sig (procedure "(lseq-any pred lseq1 lseq2 ...)" (id lseq-any))) (p "Applies " (tt "pred") " to successive elements of the lseqs, returning true if " (tt "pred") " returns true on any application. If an application returns a true value, " (tt "lseq-any") " immediately returns that value. Otherwise, it iterates until a true value is produced or one of the lseqs runs out of values; in the latter case, " (tt "lseq-any") " returns " (tt "#f") ". It is an error if " (tt "pred") " does not accept the same number of arguments as there are lseqs and return a boolean result.") (p "Note the difference between " (tt "lseq-find") " and " (tt "lseq-any") " -- " (tt "lseq-find") " returns the element that satisfied the predicate; " (tt "lseq-any") " returns the true value that the predicate produced.") (p "Like " (tt "lseq-every") ", " (tt "lseq-any") "'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 "(lseq-any integer? '(a 3 b 2.7))       ;=> #t\n(lseq-any integer? '(a 3.1 b 2.7))     ;=> #f\n(lseq-any < '(3 1 4 1 5) '(2 7 1 8 2)) ;=> #t\n\n(define (factorial n)\n  (cond\n    ((< n 0) #f)\n    ((= n 0) 1)\n    (else (* n (factorial (- n 1))))))\n(lseq-any factorial '(-1 -2 3 4))      ;=> 6"))
(def (sig (procedure "(lseq-every pred lseq1 lseq2 ...)" (id lseq-every))) (p "Applies " (tt "pred") " to successive elements of the lseqs, returning true if the predicate returns true on every application. If an application returns a false value, " (tt "lseq-every") " immediately returns that value. Otherwise, it iterates until a false value is produced or one of the lseqs runs out of values; in the latter case, " (tt "lseq-every") " returns the last value returned by " (tt "pred") ", or " (tt "#t") " if " (tt "pred") " was never invoked. It is an error if " (tt "pred") " does not accept the same number of arguments as there are lseqs and return a boolean result.") (p "Like " (tt "lseq-any") ", " (tt "lseq-every") "'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 "(lseq-every factorial '(1 2 3 4)) ;=> 24"))
(def (sig (procedure "(lseq-index pred lseq1 lseq2 ...)" (id lseq-index))) (p "Return the index of the leftmost element that satisfies " (tt "pred") ".") (p "Applies " (tt "pred") " to successive elements of the lseqs, returning an index usable with " (tt "lseq-ref") " if the predicate returns true. Otherwise, it iterates until one of the lseqs runs out of values, in which case " (tt "#f") " is returned.  It is an error if " (tt "pred") " does not accept the same number of arguments as there are lseqs and return a boolean result.") (p "The iteration stops when one of the lseqs runs out of values; in this case, " (tt "lseq-index") " returns " (tt "#f") ".") (highlight scheme "(lseq-index even? '(3 1 4 1 5 9))                ;=> 2\n(lseq-index < '(3 1 4 1 5 9 2 5 6) '(2 7 1 8 2)) ;=> 1\n(lseq-index = '(3 1 4 1 5 9 2 5 6) '(2 7 1 8 2)) ;=> #f"))
(def (sig (procedure "(lseq-member x lseq [ pred ])" (id lseq-member)) (procedure "(lseq-memq x lseq)" (id lseq-memq)) (procedure "(lseq-memv x lseq)" (id lseq-memv))) (p "These procedures return the longest tail of " (tt "lseq") " whose first element is " (tt "x") ", where the tails of " (tt "lseq") " are the non-empty lseqs returned by " (tt "(lseq-drop lseq i)") " for " (tt "i") " less than the length of " (tt "lseq") ". If " (tt "x") " does not occur in " (tt "lseq") ", then " (tt "#f") " is returned. " (tt "lseq-memq") " uses " (tt "eq?") " to compare " (tt "x") " with the elements of " (tt "lseq") ", while " (tt "lseq-memv") " uses " (tt "eqv?") ", and " (tt "lseq-member") " uses " (tt "pred") ", which defaults to " (tt "equal?") ".") (highlight scheme "(lseq-memq 'a '(a b c))           ;=>  (a b c)\n(lseq-memq 'b '(a b c))           ;=>  (b c)\n(lseq-memq 'a '(b c d))           ;=>  #f\n(lseq-memq (list 'a) '(b (a) c))  ;=>  #f\n(lseq-member (list 'a)\n             '(b (a) c))          ;=>  ((a) c)\n(lseq-memq 101 '(100 101 102))    ;=>  *unspecified*\n(lseq-memv 101 '(100 101 102))    ;=>  (101 102)") (p "The equality procedure is used to compare the elements ei of " (tt "lseq") " to the key " (tt "x") " in this way: the first argument is always " (tt "x") ", and the second argument is one of the lseq elements. Thus one can reliably find the first element of lseq that is greater than five with " (tt "(lseq-member 5 lseq <)")) (p "Note that fully general lseq searching may be performed with the " (tt "lseq-find-tail") " procedure, e.g.") (highlight scheme "(lseq-find-tail even? lseq) ; Find the first elt with an even key."))
