chickadee » biglists

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.

This is provided by the Collect macro, inspired by Clojure's For macro.

Documentation

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

biglists

biglistsprocedure
biglists symprocedure

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

Append

Append xs #!rest xssprocedure

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

Assoc

Assoc keyprocedure
Assoc key xsprocedure

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

Assp

Assp ok?procedure
Assp ok? xsprocedure

returns the biglist, whose First or car passes ok?

Assq

Assq keyprocedure
Assq key xsprocedure

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

Assv

Assv keyprocedure
Assv key xsprocedure

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

At

At kprocedure
At k xsprocedure

returns the kth item of xs

BigList?

BigList? xprprocedure

type predicate

BigList->list

BigList->list xsprocedure
BigList->list k xsprocedure

transforms a possibly infinite biglist xs into a list

Cons

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

returns either a lazy or an eager biglist

Cycle

Cycle xsprocedure

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

Cycle-times

Cycle k xsprocedure

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

Drop

Drop kprocedure
Drop k xsprocedure

drops the first k items of xs

Drop-while

Drop-while ok?procedure
Drop-while ok? xsprocedure

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

Drop-until

Drop-until ok?procedure
Drop-until ok? xsprocedure

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

Eager?

Eager? xprprocedure

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

Eq?

Eq? xs ysprocedure

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

Eqp?

Eqp? =?procedure
Eqp? =? xs ysprocedure

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

Equal?

Equal? xs ysprocedure

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

Eqv?

Eqv? xs ysprocedure

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

Every?

Every? ok?procedure
Every? ok? xsprocedure

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

Filter

Filter ok?procedure
Filter ok? xsprocedure

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

Fold-left

Fold-left op initprocedure
Fold-left op init #!rest xssprocedure

folds the finite biglists xss from the left

Fold-left0

Fold-left0 opprocedure
Fold-left0 op #!rest xssprocedure

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

Fold-right

Fold-right op initprocedure
Fold-right op init #!rest xssprocedure

folds the finite biglists xss from the right

Fold-right0

Fold-right0 opprocedure
Fold-right0 op #!rest xssprocedure

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

Collect

(Collect item-xpr (var xs ok-xpr ...) (var1 xs1 ok-xpr1 ...) ...)syntax

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

For-each fnprocedure
For-each fn #!rest xssprocedure

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

First

First xsprocedure

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

Index

Index ok?procedure
Index ok? xsprocedure

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

Iterate

Iterate fnprocedure
Iterate fn xprocedure

returns an infinite list by iteratively applying fn to x

Iterate-times

Iterate-times fn timesprocedure
Iterate-times fn times xprocedure

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

Iterate-until

Iterate-until fn ok?procedure
Iterate-until fn ok? xprocedure

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

Iterate-while

Iterate-while fn ok?procedure

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

Lazy?

Lazy? xprprocedure

is xpr a lazy biglist?

Length

Length xsprocedure

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

List

List #!rest argsprocedure

creates a lazy finite biglist with items args

List?

List? xprprocedure

is xpr a finite biglist?

List-of?

List-of? #!rest oks?procedure
List-of? k #!rest oks?procedure

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

Map

Map fnprocedure
Map fn #!rest xssprocedure

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

Member

Member xprocedure
Member x xsprocedure

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

Memp

Memp ok?procedure
Memp ok? xsprocedure

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

Memq

Memq xprocedure
Memq x xsprocedure

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

Memv

Memv xprocedure
Memv x xsprocedure

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

Merge

Merge <? xs ysprocedure

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

Null?

Null? xsprocedure

is the biglist xs empty?

Print

Print k xsprocedure
Print xsprocedure

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

Range

Range uptoprocedure
Range from uptoprocedure
Range from upto stepprocedure

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

Read-foreverprocedure

creates an infinite biglist of prompted read procedures

Remove

Remove xprocedure
Remove x xsprocedure

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

Remp

Remp ok?procedure
Remp ok? xsprocedure

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

Remq

Remp xprocedure
Remp x xsprocedure

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

Remv

Remp xprocedure
Remp x xsprocedure

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

Repeat

Repeat xprocedure

returns an infinite biglist with all items x

Repeat-times

Repeat-times k xprocedure

returns a finite biglist of length k with all items x

Rest

Rest xsprocedure

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

Reverse

Reverse xsprocedure
Reversee xs ysprocedure

Append the reverse of xs to ys xs must be finite

Reverse*

Reverse* xsprocedure

retrurns the list of reverses of of all finite takes

Scan-left

Scan-left op initprocedure
Scan-left op init #!rest xssprocedure

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

Scan-right

Scan-right op initprocedure
Scan-right op init #!rest xssprocedure

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

Some?

Some? ok?procedure
Some? ok? xsprocedure

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

Sort

Sort <?procedure
Sort <? xsprocedure

sorts the finite biglist xs with respect to <?

Sorted?

Sorted? <?procedure
Sorted? <? xsprocedure

is the biglist xs finite and sorted?

Take

Take kprocedure
Take k xsprocedure

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

Take-until

Take-until ok?procedure
Take-until ok? xsprocedure

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

Take-while

Take-while ok?procedure
Take-while ok? xsprocedure

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

Unzip

Unzip xsprocedure

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

Zip

Zip xs ysprocedure

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

None

Examples

(import biglists)

(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)

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

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

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

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

(Collect (list c k)
     (c '(A B C)) ;eager
     (k (List 1 2 3 4))) ;lazy
  ;-> '((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

Feb 06, 2020

Author

Juergen Lorenz

Repository

This egg is hosted on the CHICKEN Subversion repository:

https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/biglists

If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.

License

Copyright (c) 2014-2020, 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.4
dependency on bindings removed
0.3
For macro renamed Collect
0.2
syntax of For changed
0.1.2
some typos corrected
0.1
initial import

Contents »