1. Eager and lazy lists united
    1. Rationale
    2. Documentation
      1. biglists
      2. Append
      3. Assoc
      4. Assp
      5. Assq
      6. Assv
      7. At
      8. BigList?
      9. BigList->list
      10. Cons
      11. Cycle
      12. Cycle-times
      13. Drop
      14. Drop-while
      15. Drop-until
      16. Eager?
      17. Eq?
      18. Eqp?
      19. Equal?
      20. Eqv?
      21. Every?
      22. Filter
      23. Fold-left
      24. Fold-left0
      25. Fold-right
      26. Fold-right0
      27. For
      28. For-each
      29. First
      30. Index
      31. Iterate
      32. Iterate-times
      33. Iterate-until
      34. Iterate-while
      35. Lazy?
      36. Length
      37. List
      38. List?
      39. List-of?
      40. Map
      41. Member
      42. Memp
      43. Memq
      44. Memv
      45. Merge
      46. Null?
      47. Print
      48. Range
      49. Read-forever
      50. Remove
      51. Remp
      52. Remq
      53. Remv
      54. Repeat
      55. Repeat-times
      56. Rest
      57. Reverse
      58. Reverse*
      59. Scan-left
      60. Scan-right
      61. Some?
      62. Sort
      63. Sorted?
      64. Take
      65. Take-until
      66. Take-while
      67. Unzip
      68. Zip
      69. eos
    3. Dependencies
    4. Examples
  2. Last update
  3. Author
  4. License
  5. Version History

Eager and lazy lists united

This is an attempt to unify eager and lazy list. To use this egg you should carefully note the following

Rationale

Hence they don't interfere with ordinary list routines.

Procedure arguments first, list arguments last. For example, there is no List-ref routine, use At instead.

So, curried versions can be used in Map and friends. The documentation shows both signatures, but explains only the uncurried form.

This macro has two arguments for eager biglists, and an additional third argument, finite?, for lazy biglists.

They behave differently: First returns eos at the empty biglist, and Rest returns itself at the empty biglist. Hence At can access even finite biglists at any position, it would simply return eos past the length of finite biglists.

To achieve that, bind-seq-db is already updated.

This is provided by the For macro.

Documentation

Note, that the signatures of curried and uncurried versions are listed, but only the uncurried ones are described.

biglists

[procedure] (biglists)
[procedure] (biglists sym)

The first call returns the list of exported symbols, the second documentation for the exported symbol sym.

Append

[procedure] (Append xs . xss)

appends all argument lists, provided all but the last are finite

Assoc

[procedure] (Assoc key)
[procedure] (Assoc key xs)

returns the biglist, whose First or car is Equal? to key

Assp

[procedure] (Assp ok?)
[procedure] (Assp ok? xs)

returns the biglist, whose First or car passes ok?

Assq

[procedure] (Assq key)
[procedure] (Assq key xs)

returns the biglist, whose First or car is Eq? to key

Assv

[procedure] (Assv key)
[procedure] (Assv key xs)

returns the biglist, whose First or car is Eqv? to key

At

[procedure] (At k)
[procedure] (At k xs)

returns the kth item of xs

BigList?

[procedure] (BigList? xpr)

type predicate

BigList->list

[procedure] (BigList->list xs)
[procedure] (BigList->list k xs)

transforms a possibly infinite biglist xs into a list

Cons

[syntax] (Cons x y finite?)
[syntax] (Cons x y)

returns either a lazy or an eager biglist

Cycle

[procedure] (Cycle xs)

returns an infinite biglist by appending the finite biglist xs over and over

Cycle-times

[procedure] (Cycle k xs)

returns a finite biglist by appending the finite biglist xs k times

Drop

[procedure] (Drop k)
[procedure] (Drop k xs)

drops the first k items of xs

Drop-while

[procedure] (Drop-while ok?)
[procedure] (Drop-while ok? xs)

returns the xs whith those front items x removed which pass ok?

Drop-until

[procedure] (Drop-until ok?)
[procedure] (Drop-until ok? xs)

returns the xs whith those front items x removed which don't pass ok?

Eager?

[procedure] (Eager? xpr)

is xpr an eager biglist, i.e. a normal list?

Eq?

[procedure] (Eq? xs ys)

returns #t if both lists have same length and corresponding items are eq?

Eqp?

[procedure] (Eqp? =?)
[procedure] (Eqp? =? xs ys)

returns #t if both lists have same length and corresponding items are =?

Equal?

[procedure] (Equal? xs ys)

returns #t if both lists have same length and corresponding items are equal?

Eqv?

[procedure] (Eqv? xs ys)

returns #t if both lists have same length and corresponding items are eqv?

Every?

[procedure] (Every? ok?)
[procedure] (Every? ok? xs)

returns #t if every item of the finite biglist xs passes the ok? test

Filter

[procedure] (Filter ok?)
[procedure] (Filter ok? xs)

removes all items from the biglist xs which do not pass the ok? test

Fold-left

[procedure] (Fold-left op init)
[procedure] (Fold-left op init . xss)

folds the finite biglists xss from the left

Fold-left0

[procedure] (Fold-left0 op)
[procedure] (Fold-left0 op . xss)

folds the finite biglists<procedure>(map Rest xss) from the left with init<procedure>(map First xss)</procedure>

Fold-right

[procedure] (Fold-right op init)
[procedure] (Fold-right op init . xss)

folds the finite biglists xss from the right

Fold-right0

[procedure] (Fold-right0 op)
[procedure] (Fold-right0 op . xss)

folds the finite biglists<procedure>(map Rest xss) from the right with init<procedure>(map First xss)</procedure>

For

[syntax] (For ((var xs ok-xpr ...) (var1 xs1 ok-xpr1 ...) ...) item-xpr)

creates a new list by binding var to each element of the list xs in sequence, and if it passes the checks, ok-xpr ..., inserts the value of item-xpr into the result list. The qualifieres, (var xs ok-xpr ...), are processed sequentially from left to right, so that filters of a qualifier have access to the variables of qualifiers to its left.

For-each

[procedure] (For-each fn)
[procedure] (For-each fn . xss)

applies the procedure fn to each list of items of xss at each commeon index

First

[procedure] (First xs)

returns the front item of xs, which might be eos, if xs is empty

Index

[procedure] (Index ok?)
[procedure] (Index ok? xs)

returns the index of the first item of the biglist xs, which passes the ok? test

Iterate

[procedure] (Iterate fn)
[procedure] (Iterate fn x)

returns an infinite list by iteratively applying fn to x

Iterate-times

[procedure] (Iterate-times fn times)
[procedure] (Iterate-times fn times x)

returns a finite list of lentgh times by iteratively applying fn to x

Iterate-until

[procedure] (Iterate-until fn ok?)
[procedure] (Iterate-until fn ok? x)

returns a finite list by iteratively applying fn to x until ok? returns #t on the result

Iterate-while

[procedure] (Iterate-while fn ok?)

returns a finite list by iteratively applying fn to x as long as ok? returns #t on the result

Lazy?

[procedure] (Lazy? xpr)

is xpr a lazy biglist?

Length

[procedure] (Length xs)

retuns the length of a finite biglist or #f of an infinite one

List

[procedure] (List . args)

creates a lazy finite biglist with items args

List?

[procedure] (List? xpr)

is xpr a finite biglist?

List-of?

[procedure] (List-of? . oks?)
[procedure] (List-of? k . oks?)

returs a predicate on a biglist, which checks, if every item<procedure>(or Take k item) is a finite biglist

Map

[procedure] (Map fn)
[procedure] (Map fn . xss)

maps every list of of items at fixed index of xss with function fn

Member

[procedure] (Member x)
[procedure] (Member x xs)

returns the first tail af the biglist xs whose first item is equal? to x

Memp

[procedure] (Memp ok?)
[procedure] (Memp ok? xs)

returns the first tail af the biglist xs which passes the ok? test

Memq

[procedure] (Memq x)
[procedure] (Memq x xs)

returns the first tail af the biglist xs whose first item is eqv? to x

Memv

[procedure] (Memv x)
[procedure] (Memv x xs)

returns the first tail af the biglist xs whose first item is eqv? to x

Merge

[procedure] (Merge <? xs ys)

merges two finite finite biglists xs and ys, both lazy or both eager, with respect to <?

Null?

[procedure] (Null? xs)

is the biglist xs empty?

Print

[procedure] (Print k xs)
[procedure] (Print xs)

print the items of a finite biglist, or the first k items of an infinite one

Range

[procedure] (Range upto)
[procedure] (Range from upto)
[procedure] (Range from upto step)

creates a list of numbers with given limits from defaults to 0 step defaults to 1 the list is infinite, if utpo is #f

Read-forever

[procedure] (Read-forever)

creates an infinite biglist of prompted read procedures

Remove

[procedure] (Remove x)
[procedure] (Remove x xs)

removes all items of the biglist xs, which are equal? to x

Remp

[procedure] (Remp ok?)
[procedure] (Remp ok? xs)

removes all items of the biglist xs, which pass the ok? test

Remq

[procedure] (Remp x)
[procedure] (Remp x xs)

removes all items of the biglist xs, which are eq? to x

Remv

[procedure] (Remp x)
[procedure] (Remp x xs)

removes all items of the biglist xs, which are eqv? to x

Repeat

[procedure] (Repeat x)

returns an infinite biglist with all items x

Repeat-times

[procedure] (Repeat-times k x)

returns a finite biglist of length k with all items x

Rest

[procedure] (Rest xs)

returns the rest of the biglist except the front item which might be xs itself, if empty

Reverse

[procedure] (Reverse xs)
[procedure] (Reversee xs ys)

Append the reverse of xs to ys xs must be finite

Reverse*

[procedure] (Reverse* xs)

retrurns the list of reverses of of all finite takes

Scan-left

[procedure] (Scan-left op init)
[procedure] (Scan-left op init . xss)

returns a biglist, whose item at index k is the left fold of (map (Take k) xss)

Scan-right

[procedure] (Scan-right op init)
[procedure] (Scan-right op init . xss)

returns a biglist, whose item at index k is the right fold of (map (Take k) xss)

Some?

[procedure] (Some? ok?)
[procedure] (Some? ok? xs)

returns #t if some item of the finite biglist xs passes the ok? test

Sort

[procedure] (Sort <?)
[procedure] (Sort <? xs)

sorts the finite biglist xs with respect to <?

Sorted?

[procedure] (Sorted? <?)
[procedure] (Sorted? <? xs)

is the biglist xs finite and sorted?

Take

[procedure] (Take k)
[procedure] (Take k xs)

returns the finite biglist of the first k items of the biglist xs

Take-until

[procedure] (Take-until ok?)
[procedure] (Take-until ok? xs)

returns the finite biglist of the first items of the biglist xs, which do not pass the ok? test

Take-while

[procedure] (Take-while ok?)
[procedure] (Take-while ok? xs)

returns the finite biglist of the first items of the biglist xs, which do pass the ok? test

Unzip

[procedure] (Unzip xs)

returns two values, the sublists of biglist xs of even or uneven index

Zip

[procedure] (Zip xs ys)

merges the biglists xs and ys by alternatively Consing (First xs) or (First ys) to the result biglist. Works for unfinite biglists as well.

eos

end-of-sequence indicator

Dependencies

bindings

Examples


(import biglists bindings)

(define ones (Cons 1 ones #f))

(First eos) ;-> eos

(At 2 '(0 1 2 3 4)) ;-> 2

(At 3 (List 0 1 2 3 4) ;-> 3

(List? (List 0 1 2 3 4) ;-> #t

(List? '(0 1 2 3 4)) ;-> #t

(BigList->list (Take 4 integers)) ;-> '(0 1 2 3)

(First (Drop 4 integers)) ;-> 4

(BigList->list (Reverse (List 0 1 2 3))) ;-> '(3 2 1 0)

(Fold-right + 0 (List 1 2 3)) ;-> 6

(Fold-left + 0 '(1 2 3)) ;-> 6

(Length  (Scan-right + 0 four four)) ;-> 4

(BigList->list 12 (Zip (List 0 1 2 3) integers))
  ;-> '(0 0 1 1 2 2 3 3 4 5 6 7)

(BigList->list 10 (nth-value 0 (Unzip integers)))
  ;-> '(0 2 4 6 8 10 12 14 16 18)

(BigList->list 10 (nth-value 1 (Unzip integers)))
  ;-> '(1 3 5 7 9 11 13 15 17 19)

(Merge <= '(0 1 2 3 4) '(0 1 2 3 4))
  ;-> '(0 0 1 1 2 2 3 3 4 4)

(BigList->list (Sort <= (Append (List 0 1 2 3) (List 0 1 2 3))))
  ;-> '(0 0 1 1 2 2 3 3)

(BigList->list 10 (Memv 3 integers))
  ;-> '(3 4 5 6 7 8 9 10 11 12)

(BigList->list (Assp odd? (List (List 0 5) (List 1 6) (List 2 7))))
  ;-> '(1 6)

(BigList->list 5 (Range #f)) ;-> '(0 1 2 3 4)

(BigList->list (Iterate-times add1 5 1))
  ;-> '(1 2 3 4 5)

(bind (x . xs) integers (list x (BigList->list 5 xs)))
  ;-> '(0 (1 2 3 4 5))

(bind (x (y . ys) z) (List 1 integers 3)
  (list x y z (BigList->list 5 ys)))
  ;-> '(1 0 3 (1 2 3 4 5))

(BigList->list (For ((x (List 0 1 2 3)) (add1 x))) ;  map
  ;-> '(1 2 3 4))

(BigList->list (For ((x (List 0 1 2 3 4 5 6) (odd? x))) x)) ; filter
  ;-> '(1 3 5))

(BigList->list (For ((n (List 0 1 2 3 4 5 6) (positive? n) (even? n)))
                 (* 10 n)))
  ;-> '(20 40 60))

(BigList->list (For ((c (List 'A 'B 'C)) ;lazy
                     (k '(1 2 3 4))) ;eager
                 (list c k)))
  ;-> '((A 1) (A 2) (A 3) (A 4)
  ;     (B 1) (B 2) (B 3) (B 4)
  ;     (C 1) (C 2) (C 3) (C 4))

(For ((c '(A B C)) ;eager
      (k (List 1 2 3 4))) ;lazy
  (list c k))
  ;-> '((A 1) (A 2) (A 3) (A 4)
  ;     (B 1) (B 2) (B 3) (B 4)
  ;     (C 1) (C 2) (C 3) (C 4))

Last update

Mar 24, 2019

Author

Juergen Lorenz

License

Copyright (c) 2014-2019, Juergen Lorenz
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
Neither the name of the author nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission. 
  
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Version History

0.1.2
some typos corrected
0.1
initial import