## TOC »

- Eager and lazy lists united
- Rationale
- Documentation
- biglists
- Append
- Assoc
- Assp
- Assq
- Assv
- At
- BigList?
- BigList->list
- Cons
- Cycle
- Cycle-times
- Drop
- Drop-while
- Drop-until
- Eager?
- Eq?
- Eqp?
- Equal?
- Eqv?
- Every?
- Filter
- Fold-left
- Fold-left0
- Fold-right
- Fold-right0
- Collect
- For-each
- First
- Index
- Iterate
- Iterate-times
- Iterate-until
- Iterate-while
- Lazy?
- Length
- List
- List?
- List-of?
- Map
- Member
- Memp
- Memq
- Memv
- Merge
- Null?
- Range
- Read-forever
- Remove
- Remp
- Remq
- Remv
- Repeat
- Repeat-times
- Rest
- Reverse
- Reverse*
- Scan-left
- Scan-right
- Some?
- Sort
- Sorted?
- Take
- Take-until
- Take-while
- Unzip
- Zip
- eos

- Dependencies
- Examples

- Last update
- Author
- Repository
- License
- 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

- All routines start uppercase.

Hence they don't interfere with ordinary list routines.

- The order of arguments is consistent.

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

- Most routines are defined in curried and uncurried form.

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

- Biglists are either eager or lazy.
- Lazy biglists are either finite or infinite.
- All biglists are basically constructed with the macro Cons.

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

- The empty lazy biglist is the eos objects.
- The emppy eager biglist is '(), as usual.
- There are no Car and Cdr routines, but First and Rest instead.

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.

- List comprehensions work as well for 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

`biglists`procedure`biglists``sym`procedureThe first call returns the list of exported symbols, the second documentation for the exported symbol sym.

#### Append

`Append``xs``#!rest``xss`procedureappends all argument lists, provided all but the last are finite

#### Assoc

`Assoc``key`procedure`Assoc``key``xs`procedurereturns the biglist, whose First or car is Equal? to key

#### Assp

`Assp``ok?`procedure`Assp``ok?``xs`procedurereturns the biglist, whose First or car passes ok?

#### Assq

`Assq``key`procedure`Assq``key``xs`procedurereturns the biglist, whose First or car is Eq? to key

#### Assv

`Assv``key`procedure`Assv``key``xs`procedurereturns the biglist, whose First or car is Eqv? to key

#### At

#### BigList?

`BigList?``xpr`proceduretype predicate

#### BigList->list

`BigList->list``xs`procedure`BigList->list``k``xs`proceduretransforms a possibly infinite biglist xs into a list

#### Cons

`(Cons x y finite?)`syntax`(Cons x y)`syntaxreturns either a lazy or an eager biglist

#### Cycle

`Cycle``xs`procedurereturns an infinite biglist by appending the finite biglist xs over and over

#### Cycle-times

`Cycle``k``xs`procedurereturns a finite biglist by appending the finite biglist xs k times

#### Drop

#### Drop-while

`Drop-while``ok?`procedure`Drop-while``ok?``xs`procedurereturns the xs whith those front items x removed which pass ok?

#### Drop-until

`Drop-until``ok?`procedure`Drop-until``ok?``xs`procedurereturns the xs whith those front items x removed which don't pass ok?

#### Eager?

`Eager?``xpr`procedureis xpr an eager biglist, i.e. a normal list?

#### Eq?

`Eq?``xs``ys`procedurereturns #t if both lists have same length and corresponding items are eq?

#### Eqp?

`Eqp?``=?`procedure`Eqp?``=?``xs``ys`procedurereturns #t if both lists have same length and corresponding items are =?

#### Equal?

`Equal?``xs``ys`procedurereturns #t if both lists have same length and corresponding items are equal?

#### Eqv?

`Eqv?``xs``ys`procedurereturns #t if both lists have same length and corresponding items are eqv?

#### Every?

`Every?``ok?`procedure`Every?``ok?``xs`procedurereturns #t if every item of the finite biglist xs passes the ok? test

#### Filter

`Filter``ok?`procedure`Filter``ok?``xs`procedureremoves all items from the biglist xs which do not pass the ok? test

#### Fold-left

`Fold-left``op``init`procedure`Fold-left``op``init``#!rest``xss`procedurefolds the finite biglists xss from the left

#### Fold-left0

`Fold-left0``op`procedure`Fold-left0``op``#!rest``xss`procedurefolds the finite biglists<procedure>(map Rest xss) from the left with init<procedure>(map First xss)</procedure>

#### Fold-right

`Fold-right``op``init`procedure`Fold-right``op``init``#!rest``xss`procedurefolds the finite biglists xss from the right

#### Fold-right0

`Fold-right0``op`procedure`Fold-right0``op``#!rest``xss`procedurefolds 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 ...) ...)`syntaxcreates 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``fn`procedure`For-each``fn``#!rest``xss`procedureapplies the procedure fn to each list of items of xss at each commeon index

#### First

`First``xs`procedurereturns the front item of xs, which might be eos, if xs is empty

#### Index

`Index``ok?`procedure`Index``ok?``xs`procedurereturns the index of the first item of the biglist xs, which passes the ok? test

#### Iterate

`Iterate``fn`procedure`Iterate``fn``x`procedurereturns an infinite list by iteratively applying fn to x

#### Iterate-times

`Iterate-times``fn``times`procedure`Iterate-times``fn``times``x`procedurereturns a finite list of lentgh times by iteratively applying fn to x

#### Iterate-until

`Iterate-until``fn``ok?`procedure`Iterate-until``fn``ok?``x`procedurereturns a finite list by iteratively applying fn to x until ok? returns #t on the result

#### Iterate-while

`Iterate-while``fn``ok?`procedurereturns a finite list by iteratively applying fn to x as long as ok? returns #t on the result

#### Lazy?

`Lazy?``xpr`procedureis xpr a lazy biglist?

#### Length

`Length``xs`procedureretuns the length of a finite biglist or #f of an infinite one

#### List

`List``#!rest``args`procedurecreates a lazy finite biglist with items args

#### List?

`List?``xpr`procedureis xpr a finite biglist?

#### List-of?

`List-of?``#!rest``oks?`procedure`List-of?``k``#!rest``oks?`procedurereturs a predicate on a biglist, which checks, if every item<procedure>(or Take k item) is a finite biglist

#### Map

`Map``fn`procedure`Map``fn``#!rest``xss`proceduremaps every list of of items at fixed index of xss with function fn

#### Member

`Member``x`procedure`Member``x``xs`procedurereturns the first tail af the biglist xs whose first item is equal? to x

#### Memp

`Memp``ok?`procedure`Memp``ok?``xs`procedurereturns the first tail af the biglist xs which passes the ok? test

#### Memq

`Memq``x`procedure`Memq``x``xs`procedurereturns the first tail af the biglist xs whose first item is eqv? to x

#### Memv

`Memv``x`procedure`Memv``x``xs`procedurereturns the first tail af the biglist xs whose first item is eqv? to x

#### Merge

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

#### Null?

`Null?``xs`procedureis the biglist xs empty?

`Print``k``xs`procedure`Print``xs`procedureprint the items of a finite biglist, or the first k items of an infinite one

#### Range

`Range``upto`procedure`Range``from``upto`procedure`Range``from``upto``step`procedurecreates 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-forever`procedurecreates an infinite biglist of prompted read procedures

#### Remove

`Remove``x`procedure`Remove``x``xs`procedureremoves all items of the biglist xs, which are equal? to x

#### Remp

`Remp``ok?`procedure`Remp``ok?``xs`procedureremoves all items of the biglist xs, which pass the ok? test

#### Remq

#### Remv

#### Repeat

`Repeat``x`procedurereturns an infinite biglist with all items x

#### Repeat-times

`Repeat-times``k``x`procedurereturns a finite biglist of length k with all items x

#### Rest

`Rest``xs`procedurereturns the rest of the biglist except the front item which might be xs itself, if empty

#### Reverse

`Reverse``xs`procedure`Reversee``xs``ys`procedureAppend the reverse of xs to ys xs must be finite

#### Reverse*

`Reverse*``xs`procedureretrurns the list of reverses of of all finite takes

#### Scan-left

`Scan-left``op``init`procedure`Scan-left``op``init``#!rest``xss`procedurereturns a biglist, whose item at index k is the left fold of (map (Take k) xss)

#### Scan-right

`Scan-right``op``init`procedure`Scan-right``op``init``#!rest``xss`procedurereturns a biglist, whose item at index k is the right fold of (map (Take k) xss)

#### Some?

`Some?``ok?`procedure`Some?``ok?``xs`procedurereturns #t if some item of the finite biglist xs passes the ok? test

#### Sort

`Sort``<?`procedure`Sort``<?``xs`proceduresorts the finite biglist xs with respect to <?

#### Sorted?

`Sorted?``<?`procedure`Sorted?``<?``xs`procedureis the biglist xs finite and sorted?

#### Take

`Take``k`procedure`Take``k``xs`procedurereturns the finite biglist of the first k items of the biglist xs

#### Take-until

`Take-until``ok?`procedure`Take-until``ok?``xs`procedurereturns 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?``xs`procedurereturns the finite biglist of the first items of the biglist xs, which do pass the ok? test

#### Unzip

`Unzip``xs`procedurereturns two values, the sublists of biglist xs of even or uneven index

#### Zip

`Zip``xs``ys`proceduremerges 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

## 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