You are looking at historical revision 37379 of this page. It may differ significantly from its current revision.

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.

Hence At can access even finite biglists at any position, it would simply return eos past the length of finite biglists.

But to be consistent with the point above, there are no Car and Cdr routines, but First and Rest instead, which behave differently: First returns eos at the empty biglist, and Rest returns itself at the empty biglist.

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

This is provided by the For macro.

Documentation

At present, except the documentation procedure, biglists, this file only lists the names of the exported symbols. There documentation can be shown offline with (biglists sym).

Offline documentation is provided in all of my eggs.

biglists

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

The first call returns the list of exported symbols, the second documentation for the exported symbol sym. But note, that only the uncurried version is explained, while both signatures are noted.

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

For

For-each

First

Index

Iterate

Iterate-times

Iterate-until

Iterate-while

Lazy?

Length

List

List?

List-of?

Map

Member

Memp

Memq

Memv

Merge

Null?

Print

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

integers

nil

eos

Dependencies

bindings

Examples


(import biglists bindings)

(First nil) ;-> 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 15, 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
initial import