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

- Lazy lists
- lazy-lists
- make-lazy
- Lazy
- List?
- Length
- Cons
- Rest
- Cdr
- First
- Car
- Ref
- Null?
- Zip
- Some?
- Every?
- Fold-right*
- Fold-left*
- Fold-right
- Fold-left
- Sieve
- Split-with
- Split-at
- List->vector
- vector->List
- Sort
- Merge
- Cycle
- Reverse*
- Reverse
- Append
- Iterate
- Repeatedly
- Repeat
- input->List
- For-each
- Filter
- Map
- Assoc
- Assv
- Assq
- Assp
- Equal?
- Eqv?
- Eq?
- Equ?
- Member
- Memv
- Memq
- Memp
- Index
- Drop-upto
- Take-upto
- Drop
- Take
- List
- list->List
- List->list
- Realized?
- Primes
- Cardinals
- Interval

- Usage
- Author
- Initial version
- Updated
- License
- Version History

## Lazy lists

Lists in Scheme and Lisp are eager. Since the procedure calling regime in these languages is "Call by value", a list argument of a procedure call is completely constructed before the procedure is called. This is fine for small lists, but it excludes practically the chaining of procedure calls with large list arguments. On the other hand such a chaining is a tremendously powerful modularization technique, as demonstrated by purely functional languages like Haskell.

The traditional tools for implementation of lazy evaluation consist of the two Scheme primitives delay and force (cf. the classic "Structure and Interpretation of Computer Porgrams" by Abelson and Sussman, usually abbreveated "SICP"). But there is a better method as shown by Moritz Heidkamp in his lazy-seq Module, which in turn is meant to replace the stream datatype in SRFI-41. Moritz' approach is inspired by the Lisp dialect Clojure, which also motivated the beautiful macros in his clojurian module. The fundamental idea is to store the structure of a lazy list in a record, but to realize this list only as much as needed. This way a large (even infinite) list can be created instantaneously without realizing it and will be realized only if and as much as used.

This module is based on Heidkamp's implementation with one essential addition: The length of the list is stored in the record and can thus be referenced without realizing the whole list. After all, some operations like reverse are only meaningful for finite lists, so one must know beforehand if a list is finite to avoid infinite loops.

But knowing the length of a list at the moment of its creation, lazy lists can replace ordinary lists as a datatype. And ordinary list operations can be replaced by lazy list operations. This is the reason for the other difference of this module with Moritz' lazy-seq, a cosmetic difference: Lazy list operations are named with the same name as ordinary ones, only capitalized at the beginning. So Cons, Car, Cdr ... are the replacements of cons, car, cdr etc. Some operators have a different argument order, thow, so that the clojurian chaining macro ->> works well. The consistent argument order is as follows: procedure argument appear first, lazy list arguments last. For example (Ref n seq) replaces (list-ref seq n), (Drop n seq) replaces (list-tail seq n), etc.

Storing the length in the list record has another advantage: I can and will use my own contracts module to guard the implementation of the routines by contracts, i.e. pre- and postconditions. This allows to implement the routines proper without any defences - this is done in the module %lazy-lists - and wrap each call with the contract in the lazy-lists module. In other words, both modules have exactly the same interface (with one exception: the documentation procedure lazy-lists in the latter). The routines of the former are imported into the latter with the prefix %, so that they can be used there without contracts.

Remember, that modules written in the design-by-contract style have their documentation included, namely the equally named procedure

### lazy-lists

(lazy-lists) (lazy-list 'List)

The first call returns all available routines, the second documentation and contract of the symbol List

### make-lazy

(make-lazy len thunk) (domain (or (not len) (and (integer? len) (not (negative? len)))) (procedure? thunk) thunk returns either '(), a List or (cons val List)) (range (%List? result) (= (%Length result) len))

lazy constructor

### Lazy

<syntax> (Lazy len xpr . xprs) </syntax>

wrapper to make-lazy constructor

### List?

(List? xpr) (range (boolean? result))

lazy version of list?

### Length

(Length seq) (domain (%List? seq)) (range (or (not result) (and (integer? result) (not (negative? result)))))

lazy version of length

### Cons

(Cons var seq) (domain (%List? seq)) (range (%List? result) (or (not (%Length seq)) (= (%Length result) (+ (%Length seq) 1))))

lazy version of cons

### Rest

(Rest seq) (domain (%List? seq) (not (%Null? seq))) (range (%List? result) (or (not (%Length seq)) (= (%Length result) (- (%Length seq) 1))))

lazy version of cdr

### Cdr

(Cdr seq) (domain (%List? seq) (not (%Null? seq))) (range (%List? result) (or (not (%Length seq)) (= (%Length result) (- (%Length seq) 1))))

lazy version of cdr

### First

(First seq) (domain (%List? seq) (not (%Null? seq)))

lazy version of car

### Car

(Car seq) (domain (%List? seq) (not (%Null? seq)))

lazy version of car

### Ref

(Ref n seq) (domain (%List? seq) (integer? n) (or (not (%Length seq)) (< -1 n (%Length seq))))

lazy version of list-ref with changed argument order

### Null?

(Null? seq) (domain (%List? seq)) (range (boolean? result))

lazy version of null?

### Zip

(Zip seq1 seq2) (domain (%List? seq1) (%List? seq2)) (range (%List? result) (if(and (%Length seq1) (%Length seq2)) (= (%Length result) (+ (%Length seq1) (%Length seq2))) (not (%Length result))))

interleave two lazy lists

### Some?

(Some? ok? seq) (domain (%List? seq) (%Length seq) (procedure? ok?) "(ok? x)")

does some item of seq fulfill ok?

### Every?

(Every? ok? seq) (domain (%List? seq) (%Length seq) (procedure? ok?) "(ok? x)")

does every item of seq fulfill ok?

### Fold-right*

(Fold-right* op base . seqs) (domain (procedure? op) "(op b . ss)" ((list-of? %List?) seqs) (or (null? seqs) (all (lambda(x) (eqv? (%Length x) (%Length (car seqs)))) (cdr seqs)))) (range (%List? result) (if(null? seqs) (not (%Length result)) (eqv? (%Length result) (%Length (car seqs)))))

create a lazy list of right folds changing order or List items

### Fold-left*

(Fold-left* op base . seqs) (domain (procedure? op) "(op b . ss)" ((list-of? %List?) seqs) (or (null? seqs) (all (lambda(x) (eqv? (%Length x) (%Length (car seqs)))) (cdr seqs)))) (range (%List? result) (if(null? seqs) (not (%Length result)) (eqv? (%Length result) (%Length (car seqs)))))

create a lazy list of left folds

### Fold-right

(Fold-right op base seq . seqs) (domain (procedure? op) "(op b s . ss)" (%List? seq) ((list-of? %List?) seqs) (%Length seq) (all (lambda(x) (= (%Length x) (%Length seq))) seqs))

lazy version of fold-right

### Fold-left

(Fold-left op base seq . seqs) (domain (procedure? op) "(op b s . ss)" (%List? seq) ((list-of? %List?) seqs) (%Length seq) (all (lambda(x) (= (%Length x) (%Length seq))) seqs))

lazy version of fold-left

### Sieve

(Sieve =? seq) (domain (%List? seq) (procedure? =?) "(=? a b)") (range (%List? result) not two items =? (if(%Length seq) (<= (%Length result) (%Length seq)) (not (%Length result))))

sieve of Erathostenes with respect to =?

### Split-with

(Split-with ok? seq) (domain (%List? seq) (%Length seq) (procedure? ok?) "(ok? x)") (range (with-results(head index tail) (%List? head) (%List? tail) (integer? index) (not (negative? index)) (<= (%Length head) (%Length seq)) (<= (%Length tail) (%Length seq))))

split a lazy list at first index fulfilling ok?

### Split-at

(Split-at n seq) (domain (%List? seq) (integer? n) (not (negative? n))) (range (with-results(head tail) (%List? head) (%Length head) (<= (%Length head) n) (%List? tail) (if(%Length seq) (<= (%Length tail) (%Length seq)) (not (%Length tail)))))

split a List at fixed position

### List->vector

(List->vector seq) (domain (%List? seq) (%Length seq)) (range (vector? result) (eqv? (vector-length result) (%Length seq)))

transform a finite lazy list into a vector

### vector->List

(vector->List vec) (domain (vector? vec)) (range (%List? result) (eqv? (%Length result) (vector-length vec)))

transform a vector into a lazy list

### Sort

(Sort <? seq) (domain (procedure? <?) "(<? a b)" (%List? seq) (%Length seq)) (range (%List? result) "<? sorted" (eqv? (%Length result) (%Length seq)))

sort a finite lazy list with respect to <?

### Merge

(Merge <? seq1 seq2) (domain (procedure? <?) "(<? a b)" (%List? seq1) (%Length seq1) <? sorted (%List? seq2) (%Length seq2) <? sorted) (range (%List? result) "<? sorted" (= (%Length result) (+ (%Length seq1) (%Length seq2))))

merge two sorted lazy lists with respect to <?

### Cycle

(Cycle seq) (domain (%List? seq) (%Length seq)) (range (%List? result) (not (%Length result)))

create infinite List by cycling finite List seq

### Reverse*

(Reverse* seq) (domain (%List? seq)) (range (%List? result) (eqv? (%Length result) (%Length seq)))

List of successive reversed subLists

### Reverse

(Reverse seq) (domain (%List? seq) (%Length seq)) (range (%List? result) (%Length result) (= (%Length result) (%Length seq)))

lazy version of reverse

### Append

(Append . seqs) (domain ((list-of? %List?) seqs) (let((lst (memv #f (map %Length seqs)))) (or (not lst) (<= (length lst) 1)))) (range (%List? result) (or (not (%Length result)) (= (%Length result) (apply + (map %Length seqs)))))

lazy version of append

### Iterate

(Iterate proc x) (domain (procedure? proc) "(proc x)") (range (%List? result) (not (%Length result)))

create infinite List by applying proc succesively to x

### Repeatedly

(Repeatedly thunk) (domain (procedure? thunk)) (range (%List? result) (not (%Length result)))

create infinite List of return values of thunk

### Repeat

(Repeat x) (range (%List? result) (not (%Length result)))

create infinite List of x

### input->List

(input->List port read-proc) (domain (input-port? port) (procedure? read-proc)) (range (%List? result) (%Length result))

transform input port into List with read-proc

### For-each

(For-each proc seq . seqs) (domain (%List? seq) ((list-of? %List?) seqs) (procedure? proc) "(proc arg . args)" (all (lambda(x) (eqv? (%Length x) (%Length seq))) seqs))

lazy version of for-each

### Filter

(Filter ok? seq) (domain (%List? seq) (procedure? ok?) "(ok? x)") (range (%List? result) (or (not (%Length seq)) (<= (%Length result) (%Length seq))))

lazy version of filter

### Map

(Map proc seq . seqs) (domain (%List? seq) ((list-of? %List?) seqs) (procedure? proc) "(proc arg . args)" (all (lambda(x) (eqv? (%Length x) (%Length seq))) seqs)) (range (%List? result) (eqv? (%Length result) (%Length seq)))

lazy version of map

### Assoc

(Assoc key aseq) (domain (%List? aseq) List of pairs (%Length aseq)) (range (or (not result) (pair? result)))

lazy version of assoq

### Assv

(Assv key aseq) (domain (%List? aseq) List of pairs (%Length aseq)) (range (or (not result) (pair? result)))

lazy version of assv

### Assq

(Assq key aseq) (domain (%List? aseq) List of pairs (%Length aseq)) (range (or (not result) (pair? result)))

lazy version of assq

### Assp

(Assp ok? aseq) (domain (%List? aseq) List of pairs (%Length aseq) (procedure? ok?) "(ok? x)") (range (or (not result) (pair? result)))

return #f or first pair, whose Car fulfills ok?

### Equal?

(Equal? seq1 seq2) (domain (%List? seq1) (%List? seq2)) (range (boolean? result))

lazy version of equal?

### Eqv?

(Eqv? seq1 seq2) (domain (%List? seq1) (%List? seq2)) (range (boolean? result))

lazy version of eqv?

### Eq?

(Eq? seq1 seq2) (domain (%List? seq1) (%List? seq2)) (range (boolean? result))

lazy version of eq?

### Equ?

(Equ? =? seq1 seq2) (domain (%List? seq1) (%List? seq2) (procedure? =?) "(=? x y)") (range (boolean? result))

compare two Lists with predicate =?

### Member

(Member var seq) (domain (%List? seq) (%Length seq)) (range (%List? result) (<= (%Length result) (%Length seq)))

lazy version of member

### Memv

(Memv var seq) (domain (%List? seq) (%Length seq)) (range (%List? result) (<= (%Length result) (%Length seq)))

lazy version of memv

### Memq

(Memq var seq) (domain (%List? seq) (%Length seq)) (range (%List? result) (<= (%Length result) (%Length seq)))

lazy version of memq

### Memp

(Memp ok? seq) (domain (%List? seq) (%Length seq) (procedure? ok?) (ok? x)) (range (%List? result) (<= (%Length result) (%Length seq)))

Tail of items not fulfilling ok?

### Index

(Index ok? seq) (domain (%List? seq) (%Length seq) (procedure? ok?) "(ok? x)") (range (integer? result) (not (negative? result)))

return index of first item fulfilling ok?

### Drop-upto

(Drop-upto ok? seq) (domain (%List? seq) (%Length seq) (procedure? ok?) "(ok? x)") (range (%List? result) (<= (%Length result) (%Length seq)))

Tail of items not fulfilling ok?

### Take-upto

(Take-upto ok? seq) (domain (%List? seq) (%Length seq) (procedure? ok?) "(ok? x)") (range (%List? result) (<= (%Length result) (%Length seq)))

List of head items fulfilling ok?

### Drop

(Drop n seq) (domain (%List? seq) (integer? n) (not (negative? n))) (range (%List? result) (if(%Length seq) (= (%Length result) (max 0 (- (%Length seq) n))) (not (%Length result))))

lazy version of list-tail with changed argument order

### Take

(Take n seq) (domain (%List? seq) (integer? n) (not (negative? n))) (range (%List? result) (%Length result) (if(%Length seq) (= (%Length result) (min n (%Length seq))) (= (%Length result) n)))

List of first n items of seq

### List

(List . args) (range (%List? result) (eqv? (%Length result) (length args)))

lazy version of list

### list->List

(list->List lst) (domain (list? lst)) (range (%List? result) (eqv? (%Length result) (length lst)))

transform ordinary list into finite lazy list

### List->list

(List->list seq) (domain (%List? seq) (%Length seq)) (range (list? result))

transform finite lazy into ordinary list

### Realized?

(Realized? seq) (domain (%List? seq)) (range (boolean? result))

Is seq realized?

### Primes

(Primes) (range (%List? result) (not (%Length result)))

lazy list of non prime numbers

### Cardinals

(Cardinals) (range (%List? result) (not (%Length result)))

lazy list of non negative integers

### Interval

(Interval from upto) (domain (integer? from) (integer? upto)) (range (%List result) (= (%Length result) (abs (- upto from))))

List of integers from (included) upto (excluded)

## Usage

(use lazy-lists contracts) == Examples <enscript highlight=scheme> (require-library clojurian-syntax lazy-lists contracts) (import lazy-lists clojurian-syntax contracts) ;;; (run xpr0 xpr1 ...) ;;; ------------------- (define(run . xprs) (letloop((xprs xprs)) (if(null? xprs) (print "All tests passed!") (if(car xprs) (loop(cdr xprs)) (error 'run "#### Some test failed! ####"))))) (define(cons-right var lst) (if(null? lst) (cons var lst) (cons (car lst) (cons-right var (cdr lst))))) (define(Within eps seq) (letloop((seq seq)) (let((a (Ref 0 seq)) (b (Ref 1 seq))) (if(< (abs (- a b)) eps) b (loop(Rest seq)))))) (define(Relative eps seq) (letloop((seq seq)) (let((a (Ref 0 seq)) (b (Ref 1 seq))) (if(<= (abs (/ a b)) (* (abs b) eps)) b (loop(Rest seq)))))) (define(Newton x) ; fixed point for square root (lambda(a) (/ (+ a (/ x a)) 2))) (define(Sums seq) ; List of sums (letrec ((sums (Cons 0 (Map + seq (Lazy (Length seq) sums))))) (Rest sums))) (define(First-five) (List 0 1 2 3 4)) (define(Fibs) (Append (List 0 1) (Lazy #f (Map + (Rest (Fibs)) (Fibs))))) (defineport (open-input-file "lazy-lists.scm")) (defineinput (input->List port read-line)) (run (= (Length (First-five)) 5) (= (Length (Rest (First-five))) 4) (->> (Cardinals) (Rest) (Length) (eq? #f)) (->> (Cardinals) (Take 5) (Length) (= 5)) (->> (Cardinals) (Length) (eq? #f)) (->> (Cardinals) (Drop 5) (Length) (eq? #f)) (->> (Cardinals) (Drop 5) (First) (= 5)) (->> (First-five) (List->list) (equal? '(0 1 2 3 4))) (->> (Cardinals) (Take 5) (List->list) (equal? '(0 1 2 3 4))) (->> (Interval 2 10) (Length) (= (- 10 2))) (->> (Interval 2 10) (List->list) (equal? '(2 3 4 5 6 7 8 9))) (->> (Interval 10 2) (List->list) (equal? '(10 9 8 7 6 5 4 3))) (equal? (receive (head index tail) (Split-with (cut = <> 3) (First-five)) (cons (First tail) (List->list head))) '(3 0 1 2)) (equal? (receive (head index tail) (Split-with (cut = <> 5) (Take 10 (Cardinals))) (append (List->list tail) (List->list head))) '(5 6 7 8 9 0 1 2 3 4)) (->> (First-five) (Index (cut = <> 2)) (= 2)) (->> (First-five) (Index (cut = <> 20)) (= 5)) (->> (Cardinals) (Take 10) (Take-upto (cut = <> 5)) (List->list) (equal? '(0 1 2 3 4))) (->> (Cardinals) (Take 10) (Take-upto (cut = <> 5)) (Length) (= 5)) (->> (Cardinals) (Take 10) (Drop-upto (cut = <> 5)) (Length) (= 5)) (->> (Cardinals) (Take 10) (Drop-upto (cut = <> 5)) (First) (= 5)) (->> (First-five) (Drop-upto (cut = <> 2)) (Length) (= 3)) (->> (First-five) (Drop-upto (cut = <> 2)) (First) (= 2)) (->> (First-five) (Memp odd?) (List->list) (equal? '(1 2 3 4))) (->> (Cardinals) (Take 10) (Memv 5) (List->list) (equal? '(5 6 7 8 9))) (->> (Cardinals) (Map (lambda(x) (list x x))) (Take 10) (Assv 5) (equal? '(5 5))) (->> (First-five) (Map (lambda(x) (list x x))) (Assv 10) (eq? #f)) (->> (Cardinals) (Equal? (Cardinals)) (eq? #f)) (->> (Cardinals) (Equal? (First-five)) (eq? #f)) (->> (First-five) (Equal? (First-five)) (eq? #t)) (->> (Cardinals) (Take 10) (Length) (= 10)) (->> (Cardinals) (Drop 1) (Filter odd?) (Take 5) (List->list) (equal? '(1 3 5 7 9))) (->> (Cardinals) (Length) (eq? #f)) (->> (First-five) (Map add1) (List->list) (equal? '(1 2 3 4 5))) (->> (Map + (First-five) (Take 5 (Cardinals))) (List->list) (equal? '(0 2 4 6 8))) (->> (Map + (Cardinals) (Cardinals)) (Length) (eq? #f)) (->> (Filter odd? (First-five)) (Length) (= 2)) (->> (Filter odd? (First-five)) (List->list) (equal? '(1 3))) (->> (Filter odd? (Cardinals)) (Length) (eq? #f)) (->> (Zip (Cardinals) (Cardinals)) (Sieve =) (Ref 20) (= 20)) (->> (Zip (First-five) (First-five)) (Sieve =) (List->list) (equal? '(0 1 2 3 4))) (->> (Ref 25 (Cardinals)) (= 25)) (->> (Ref 2 (First-five)) (= 2)) (->> (Repeat #f) (Take 3) (List->list) (equal? '(#f #f #f))) (->> (Repeatedly (lambda() 1))(Take 3) (List->list) (equal? '(1 1 1))) (->> (Iterate add1 0) (Take 3) (List->list) (equal? '(0 1 2))) (->> (Iterate add1 0) (Length) (eq? #f)) (->> (Append (First-five) (First-five)) (Length) (= 10)) (->> (Append (First-five) (First-five)) (List->list) (equal? '(0 1 2 3 4 0 1 2 3 4))) (->> (Append (First-five) (Cardinals)) (Take 12) (List->list) (equal? '(0 1 2 3 4 0 1 2 3 4 5 6))) (->> (Append (First-five) (Cardinals)) (Length) (eq? #f)) (->> (First-five) (Reverse) (List->list) (equal? '(4 3 2 1 0))) (->> (Cardinals) (Take 5) (Reverse) (List->list) (equal? '(4 3 2 1 0))) (->> (First-five) (Reverse) (Length) (= 5)) (->> (Cardinals) (Reverse*) (Length) (eq? #f)) (->> (Cardinals) (Reverse*) (Ref 5) (List->list) (equal? '(5 4 3 2 1 0))) (->> (Cycle (First-five)) (Take 10) (List->list) (equal? '(0 1 2 3 4 0 1 2 3 4))) (->> (Cycle (First-five)) (Length) (eq? #f)) (->> (Sort < (First-five)) (List->list) (equal? '(0 1 2 3 4))) (->> (Sort < (First-five)) (Length) (= 5)) (->> (Sort < (List 3 1 0 2 4)) (List->list) (equal? '(0 1 2 3 4))) (equal? (receive (head tail) (Split-at 5 (Cardinals)) (cons (First tail) (List->list head))) '(5 0 1 2 3 4)) (equal? (receive (head tail) (Split-at 15 (Take 5 (Cardinals))) (append (List->list tail) (List->list head))) '(0 1 2 3 4)) (->> (Cardinals) (Take 5) (Fold-left + 0) (= 10)) (->> (Fold-left + 0 (First-five) (First-five)) (= 20)) (->> (List 1 2 3 4) (Fold-left * 1) (= 24)) (->> (Cardinals) (Take 5) (Fold-left cons '()) (equal? '(((((() . 0) . 1) . 2) . 3) . 4))) (->> (Cardinals) (Fold-left* cons '()) (Ref 4) (equal? '(((((() . 0) . 1) . 2) . 3) . 4))) (->> (Cardinals) (Take 5) (Fold-right + 0) (= 10)) (->> (Fold-right + 0 (First-five) (First-five)) (= 20)) (->> (First-five) (Fold-right cons '()) (equal? '(0 1 2 3 4))) ; list (->> (First-five) (Fold-right cons '(a b c)) (equal? '(0 1 2 3 4 a b c))) ; append (->> (Cardinals) (Fold-right* cons '()) (Ref 4) (equal? '(4 3 2 1 0))) ; note changed order (->> (Cardinals) (Fold-right* cons-right '()) (Ref 4) (equal? '(0 1 2 3 4))) (->> (Cardinals) (Fold-right* cons '(a b c)) (Ref 4) (equal? '(4 3 2 1 0 a b c))) ; note changed order (->> (Cardinals) (Fold-right* cons-right '(a b c)) (Ref 4) (equal? '(a b c 0 1 2 3 4))) (->> (vector->List '#(0 1 2 3 4)) (List->list) (equal? '(0 1 2 3 4))) (->> (vector->List '#()) (Null?)) (->> (Take 5 (Cardinals)) (List->vector) (equal? '#(0 1 2 3 4))) (->> (List->vector (First-five)) (equal? '#(0 1 2 3 4))) (->> (List->vector Nil) (equal? '#())) (->> (Filter odd? (Cardinals)) (Take 15) (Every? odd?) (eq? #t)) (->> (Take 15 (Cardinals)) (Every? odd?) (eq? #f)) (->> (Every? odd? Nil) (eq? #t)) (->> (Some? odd? Nil) (eq? #f)) (->> (Filter even? (Cardinals)) (Take 5) (Some? odd?) (eq? #f)) (->> (Some? odd? (First-five)) (eq? #t)) (->> (Zip (Cardinals) (First-five)) (Length) (eq? #f)) (->> (Zip (First-five) (Cardinals)) (Length) (eq? #f)) (->> (Zip (Cardinals) (Cardinals)) (Length) (eq? #f)) (->> (Zip (Cardinals) (First-five)) (Take 14) (Eqv? (List 0 0 1 1 2 2 3 3 4 4 5 6 7 8))) (->> (Zip (Cardinals) (Cardinals)) (Take 14) (Eqv? (List 0 0 1 1 2 2 3 3 4 4 5 5 6 6))) (->> (Zip (First-five) (First-five)) (Length) (= 10)) (->> (Zip (First-five) (First-five)) (Eqv? (List 0 0 1 1 2 2 3 3 4 4))) (->> (Primes) (Ref 50) (= 233)) (->> (Primes) (Take 5) (Eqv? (List 2 3 5 7 11))) (->> (Fibs) (Take 10) (Eqv? (List 0 1 1 2 3 5 8 13 21 34))) ;; compute square root (let((eps 0.000001)) (< (abs (- (sqrt 2) (Within eps (Iterate (Newton 2) 2)))) eps)) (->> (First-five) (Sums) (List->list) (equal? '(0 1 3 6 10))) )

## Author

## Initial version

Aug 1, 2012

## Updated

## License

Copyright (c) 2012, 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