You are looking at historical revision 27201 of this page. It may differ significantly from its current revision.
- Lazy lists
- lazy-lists
- make-lazy
- Lazy
- Nil
- 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
- Examples
- 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 arguments 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 defenses - 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
[procedure] (lazy-lists [sym])returns all available routines of the module when called without an argument, but when called with one of these routines as a symbol, returns its contract and documentation string.
make-lazy
[procedure] (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)wrapper to make-lazy constructor
Nil
empty lazy list
List?
[procedure] (List? xpr)(range (boolean? result))
lazy version of list?
Length
[procedure] (Length seq)(domain (%List? seq)) (range (or (not result) (and (integer? result) (not (negative? result)))))
lazy version of length
Cons
[procedure] (Cons var seq)(domain (%List? seq)) (range (%List? result) (or (not (%Length seq)) (= (%Length result) (+ (%Length seq) 1))))
lazy version of cons
Rest
[procedure] (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
[procedure] (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
[procedure] (First seq)(domain (%List? seq) (not (%Null? seq)))
lazy version of car
Car
[procedure] (Car seq)(domain (%List? seq) (not (%Null? seq)))
lazy version of car
Ref
[procedure] (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?
[procedure] (Null? seq)(domain (%List? seq)) (range (boolean? result))
lazy version of null?
Zip
[procedure] (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?
[procedure] (Some? ok? seq)(domain (%List? seq) (%Length seq) (procedure? ok?) "(ok? x)")
does some item of seq fulfill ok?
Every?
[procedure] (Every? ok? seq)(domain (%List? seq) (%Length seq) (procedure? ok?) "(ok? x)")
does every item of seq fulfill ok?
Fold-right*
[procedure] (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*
[procedure] (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
[procedure] (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
[procedure] (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
[procedure] (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
[procedure] (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
[procedure] (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
[procedure] (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
[procedure] (vector->List vec)(domain (vector? vec)) (range (%List? result) (eqv? (%Length result) (vector-length vec)))
transform a vector into a lazy list
Sort
[procedure] (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
[procedure] (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
[procedure] (Cycle seq)(domain (%List? seq) (%Length seq)) (range (%List? result) (not (%Length result)))
create infinite List by cycling finite List seq
Reverse*
[procedure] (Reverse* seq)(domain (%List? seq)) (range (%List? result) (eqv? (%Length result) (%Length seq)))
List of successive reversed subLists
Reverse
[procedure] (Reverse seq)(domain (%List? seq) (%Length seq)) (range (%List? result) (%Length result) (= (%Length result) (%Length seq)))
lazy version of reverse
Append
[procedure] (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
[procedure] (Iterate proc x)(domain (procedure? proc) "(proc x)") (range (%List? result) (not (%Length result)))
create infinite List by applying proc succesively to x
Repeatedly
[procedure] (Repeatedly thunk)(domain (procedure? thunk)) (range (%List? result) (not (%Length result)))
create infinite List of return values of thunk
Repeat
[procedure] (Repeat x)(range (%List? result) (not (%Length result)))
create infinite List of x
input->List
[procedure] (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
[procedure] (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
[procedure] (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
[procedure] (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
[procedure] (Assoc key aseq)(domain (%List? aseq) "List of pairs" (%Length aseq)) (range (or (not result) (pair? result)))
lazy version of assoq
Assv
[procedure] (Assv key aseq)(domain (%List? aseq) "List of pairs" (%Length aseq)) (range (or (not result) (pair? result)))
lazy version of assv
Assq
[procedure] (Assq key aseq)(domain (%List? aseq) "List of pairs" (%Length aseq)) (range (or (not result) (pair? result)))
lazy version of assq
Assp
[procedure] (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?
[procedure] (Equal? seq1 seq2)(domain (%List? seq1) (%List? seq2)) (range (boolean? result))
lazy version of equal?
Eqv?
[procedure] (Eqv? seq1 seq2)(domain (%List? seq1) (%List? seq2)) (range (boolean? result))
lazy version of eqv?
Eq?
[procedure] (Eq? seq1 seq2)(domain (%List? seq1) (%List? seq2)) (range (boolean? result))
lazy version of eq?
Equ?
[procedure] (Equ? =? seq1 seq2)(domain (%List? seq1) (%List? seq2) (procedure? =?) "(=? x y)") (range (boolean? result))
compare two Lists with predicate =?
Member
[procedure] (Member var seq)(domain (%List? seq) (%Length seq)) (range (%List? result) (<= (%Length result) (%Length seq)))
lazy version of member
Memv
[procedure] (Memv var seq)(domain (%List? seq) (%Length seq)) (range (%List? result) (<= (%Length result) (%Length seq)))
lazy version of memv
Memq
[procedure] (Memq var seq)(domain (%List? seq) (%Length seq)) (range (%List? result) (<= (%Length result) (%Length seq)))
lazy version of memq
Memp
[procedure] (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
[procedure] (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
[procedure] (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
[procedure] (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
[procedure] (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
[procedure] (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
[procedure] (List . args)(range (%List? result) (eqv? (%Length result) (length args)))
lazy version of list
list->List
[procedure] (list->List lst)(domain (list? lst)) (range (%List? result) (eqv? (%Length result) (length lst)))
transform ordinary list into finite lazy list
List->list
[procedure] (List->list seq)(domain (%List? seq) (%Length seq)) (range (list? result))
transform finite lazy into ordinary list
Realized?
[procedure] (Realized? seq)(domain (%List? seq)) (range (boolean? result))
Is seq realized?
Primes
[procedure] (Primes)(range (%List? result) (not (%Length result)))
lazy list of non prime numbers
Cardinals
[procedure] (Cardinals)(range (%List? result) (not (%Length result)))
lazy list of non negative integers
Interval
[procedure] (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
(require-library lazy-lists) (import lazy-lists) ;;; (run xpr0 xpr1 ...) ;;; ------------------- (define (run . xprs) (let loop ((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) (let loop ((seq seq)) (let ((a (Ref 0 seq)) (b (Ref 1 seq))) (if (< (abs (- a b)) eps) b (loop (Rest seq)))))) (define (Relative eps seq) (let loop ((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))))) ;(define port (open-input-file "lazy-lists.scm")) ;(define input (input->List port read-line)) (run (= (Length (First-five)) 5) (= (Length (Rest (First-five))) 4) (eq? (Length (Rest (Cardinals))) #f) (= (Length (Take 5 (Cardinals))) 5) (eq? (Length (Cardinals)) #f) (eq? (Length (Drop 5 (Cardinals))) #f) (= (First (Drop 5 (Cardinals))) 5) (equal? (List->list (First-five)) '(0 1 2 3 4)) (equal? (List->list (Take 5 (Cardinals))) '(0 1 2 3 4)) (= (Length (Interval 2 10)) (- 10 2)) (equal? (List->list (Interval 2 10)) '(2 3 4 5 6 7 8 9)) (equal? (List->list (Interval 10 2)) '(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)) (= (Index (cut = <> 2) (First-five)) 2) (= (Index (cut = <> 20) (First-five)) 5) (equal? (List->list (Take-upto (cut = <> 5) (Take 10 (Cardinals)))) '(0 1 2 3 4)) (= (Length (Take-upto (cut = <> 5) (Take 10 (Cardinals)))) 5) (= (Length (Drop-upto (cut = <> 5) (Take 10 (Cardinals)))) 5) (= (First (Drop-upto (cut = <> 5) (Take 10 (Cardinals)))) 5) (= (Length (Drop-upto (cut = <> 2) (First-five))) 3) (= (First (Drop-upto (cut = <> 2) (First-five))) 2) (equal? (List->list (Memp odd? (First-five))) '(1 2 3 4)) (equal? (List->list (Memv 5 (Take 10 (Cardinals)))) '(5 6 7 8 9)) (equal? (Assv 5 (Take 10 (Map (lambda (x) (list x x)) (Cardinals)))) '(5 5)) (eq? (Assv 10 (Map (lambda (x) (list x x)) (First-five))) #f) (eq? (Equal? (Cardinals) (Cardinals)) #f) (eq? (Equal? (Cardinals) (First-five)) #f) (eq? (Equal? (First-five) (First-five)) #t) (= (Length (Take 10 (Cardinals))) 10) (equal? (List->list (Take 5 (Filter odd? (Drop 1 (Cardinals))))) '(1 3 5 7 9)) (eq? (Length (Cardinals)) #f) (equal? (List->list (Map add1 (First-five))) '(1 2 3 4 5)) (equal? (List->list (Map + (First-five) (Take 5 (Cardinals)))) '(0 2 4 6 8)) (eq? (Length (Map + (Cardinals) (Cardinals))) #f) (= (Length (Filter odd? (First-five))) 2) (equal? (List->list (Filter odd? (First-five))) '(1 3)) (eq? (Length (Filter odd? (Cardinals))) #f) (= (Ref 20 (Sieve = (Zip (Cardinals) (Cardinals)))) 20) (equal? (List->list (Sieve = (Zip (First-five) (First-five)))) '(0 1 2 3 4)) (= (Ref 25 (Cardinals)) 25) (= (Ref 2 (First-five)) 2) (equal? (List->list (Take 3 (Repeat #f))) '(#f #f #f)) (equal? (List->list (Take 3 (Repeatedly (lambda () 1)))) '(1 1 1)) (equal? (List->list (Take 3 (Iterate add1 0))) '(0 1 2)) (eq? (Length (Iterate add1 0)) #f) (= (Length (Append (First-five) (First-five))) 10) (equal? (List->list (Append (First-five) (First-five))) '(0 1 2 3 4 0 1 2 3 4)) (equal? (List->list (Take 12 (Append (First-five) (Cardinals)))) '(0 1 2 3 4 0 1 2 3 4 5 6)) (eq? (Length (Append (First-five) (Cardinals))) #f) (equal? (List->list (Reverse (First-five))) '(4 3 2 1 0)) (equal? (List->list (Reverse (Take 5 (Cardinals)))) '(4 3 2 1 0)) (= (Length (Reverse (First-five))) 5) (eq? (Length (Reverse* (Cardinals))) #f) (equal? (List->list (Ref 5 (Reverse* (Cardinals)))) '(5 4 3 2 1 0)) (equal? (List->list (Take 10 (Cycle (First-five)))) '(0 1 2 3 4 0 1 2 3 4)) (eq? (Length (Cycle (First-five))) #f) (equal? (List->list (Sort < (First-five))) '(0 1 2 3 4)) (= (Length (Sort < (First-five))) 5) (equal? (List->list (Sort < (List 3 1 0 2 4))) '(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)) (= (Fold-left + 0 (Take 5 (Cardinals))) 10) (= (Fold-left + 0 (First-five) (First-five)) 20) (= (Fold-left * 1 (List 1 2 3 4)) 24) (equal? (Fold-left cons '() (Take 5 (Cardinals))) '(((((() . 0) . 1) . 2) . 3) . 4)) (equal? (Ref 4 (Fold-left* cons '() (Cardinals))) '(((((() . 0) . 1) . 2) . 3) . 4)) (= (Fold-right + 0 (Take 5 (Cardinals))) 10) (= (Fold-right + 0 (First-five) (First-five)) 20) (equal? (Fold-right cons '() (First-five)) '(0 1 2 3 4)) ; list (equal? (Fold-right cons '(a b c) (First-five)) '(0 1 2 3 4 a b c)) ; append (equal? (Ref 4 (Fold-right* cons '() (Cardinals))) '(4 3 2 1 0)) ; note changed order (equal? (Ref 4 (Fold-right* cons-right '() (Cardinals))) '(0 1 2 3 4)) (equal? (Ref 4 (Fold-right* cons '(a b c) (Cardinals))) '(4 3 2 1 0 a b c)) ; note changed order (equal? (Ref 4 (Fold-right* cons-right '(a b c) (Cardinals))) '(a b c 0 1 2 3 4)) (equal? (List->list (vector->List '#(0 1 2 3 4))) '(0 1 2 3 4)) (Null? (vector->List '#())) (equal? (List->vector (Take 5 (Cardinals))) '#(0 1 2 3 4)) (equal? (List->vector (First-five)) '#(0 1 2 3 4)) (equal? (List->vector Nil) '#()) (eq? (Every? odd? (Take 15 (Filter odd? (Cardinals)))) #t) (eq? (Every? odd? (Take 15 (Cardinals))) #f) (eq? (Every? odd? Nil) #t) (eq? (Some? odd? Nil) #f) (eq? (Some? odd? (Take 5 (Filter even? (Cardinals)))) #f) (eq? (Some? odd? (First-five)) #t) (eq? (Length (Zip (Cardinals) (First-five))) #f) (eq? (Length (Zip (First-five) (Cardinals))) #f) (eq? (Length (Zip (Cardinals) (Cardinals))) #f) (= (Length (Zip (First-five) (First-five))) 10) (Eqv? (Take 14 (Zip (Cardinals) (First-five))) (List 0 0 1 1 2 2 3 3 4 4 5 6 7 8)) (Eqv? (Take 14 (Zip (Cardinals) (Cardinals))) (List 0 0 1 1 2 2 3 3 4 4 5 5 6 6)) (Eqv? (Zip (First-five) (First-five)) (List 0 0 1 1 2 2 3 3 4 4)) (= (Ref 50 (Primes)) 233) (Eqv? (Take 5 (Primes)) (List 2 3 5 7 11)) (Eqv? (Take 10 (Fibs)) (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)) (equal? (List->list (Sums (First-five))) '(0 1 3 6 10)) )
Author
Initial version
Aug 1, 2012
Updated
Aug 5, 2012
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.2
- dependency on clojurian removed
- 0.1
- initial import