(import biglists (only bindings bind) simple-tests) ;;; (At 10000 primes) ;;; ----------------- ;;; Interpreted ;;; takes 11.472s CPU-time without finite?, ;;; and 12,52 s with finite? argument ;;; that's acceptable, imho ;;; with BigList? checks for First and Rest it results in 28.55s. ;;; Compiled (with additional finite? arg of Cons) ;;; without First/Rest checks 9.023s CPU ;;; with First/Rest checks 10.224s CPU (define tree (Cons 1 (Cons (Cons 2 eos #t) (Cons 3 eos #t) #t) #t)) ;(Cons 1 (Cons (Cons 2 eos) (Cons 3 eos)))) (define ones (Cons 1 ones #f)) (define twos (Map + ones ones)) (define integers (Iterate add1 0)) (define positive-integers (Cons 1 (Map + ones positive-integers) #f)) ;(Cons 1 (Map + ones positive-integers))) (define fibs (Cons 0 (Cons 1 (Map + (Rest fibs) fibs) #f) #f)) ;(Cons 0 (Cons 1 (Map + (Rest fibs) fibs)))) (define primes ;(Cons 2 (Filter prime? (integers-from 3)) #f)) (Cons 2 (Filter prime? (Drop 3 integers)) #f)) ;(Cons 2 (Filter prime? (integers-from 3)))) ;(define (divisible? x y) (zero? (remainder x y))) (define (prime? n) (let loop ((ps primes)) (cond ((> (* (First ps) (First ps)) n) #t) ((zero? (remainder n (First ps))) #f) (else (loop (Rest ps)))))) (define four (List 0 1 2 3)) (define five (list 0 1 2 3 4)) (define-test (biglists?) (= (First (Cons 1 2 #f)) 1) (= (Rest (Cons 1 2 #f)) 2) (= (First tree) 1) (= (First (First (Rest tree))) 2) (= (First (Rest (Rest tree))) 3) (= (At 5 ones) 1) (= (At 2 five) 2) (not (List? ones)) (= (At 5 twos) 2) (= (At 5 (Map (lambda (x) (* 10 x)) twos)) 20) (= (At 3 (List 0 1 2 3 4)) 3) (BigList? eos) (Null? eos) (List? eos) (not (Null? ones)) (= (At 5 integers) 5) (= (At 5 (Map * integers integers)) 25) (= (At 5 (Map + ones integers)) 6) (= (At 3 (Map + four five)) 6) (zero? (First (Take 3 integers))) (equal? (Take 2 five) '(0 1)) (equal? (Take-while (cut < <> 2) five) '(0 1)) (equal? (BigList->list (Take-while (cut < <> 2) integers)) '(0 1)) (equal? (BigList->list (Take-while (cut < <> 2) integers)) '(0 1)) (equal? (Take-until (cut = <> 2) five) '(0 1)) (equal? (BigList->list (Take-until (cut = <> 2) integers)) '(0 1)) (= (At 5 (Filter even? integers)) 10) (equal? (Filter even? five) '(0 2 4)) (= (At 5 positive-integers) 6) (not (List? fibs)) (equal? (BigList->list 5 fibs) '(0 1 1 2 3)) (equal? (BigList->list 5 primes) '(2 3 5 7 11)) (not (List? primes)) (BigList? fibs) (BigList? primes) (BigList? integers) (not (List? integers)) (BigList? ones) (BigList? tree) ((List-of? number? odd?) '(1 3 5 7)) ((List-of? number? odd?) (List 1 3 5 7)) ((List-of? integer?) (Take 10 integers)) (not ((List-of? odd?) four)) (not ((List-of? odd?) five)) (equal? (BigList->list four) '(0 1 2 3)) (= (Fold-right + 0 five) 10) (= (Fold-left + 0 five) 10) (= (Fold-right + 0 four) 6) (= (Fold-left + 0 four) 6) (= (Fold-left0 + four) 6) (= (Fold-left0 + five) 10) (BigList? (Take 5 integers)) (List? (Take 5 integers)) (= (Fold-right + 0 (Take 5 integers) (Take 5 integers)) 20) (= (Fold-right + 0 (Take 3 integers) integers) 6) (= (Fold-left + 0 (Take 3 integers) integers) 6) (equal? (BigList->list 5 (Scan-right + 0 integers integers)) '(0 0 2 6 12)) (equal? (BigList->list 5 (Scan-left + 0 integers integers)) '(0 0 2 6 12)) (not (List? (Scan-left + 0 integers integers))) (List? (Scan-left + 0 four four)) (List? (Scan-right + 0 four integers)) (not (Length integers)) (not (Length (Scan-right + 0 integers))) (print "XXX " (BigList->list (Scan-right + 0 five))) (= (At 2 (Scan-right + 0 five)) 1) (= (Length (Scan-right + 0 five)) 5) (= (Length (Scan-right + 0 five five)) 5) (= (Length (Scan-left + 0 five five)) 5) (= (At 3 (Scan-right + 0 four)) 3) (Null? (At 4 (Scan-right + 0 four))) (Null? (At 4 (Scan-right + 0 four four))) (eq? (At 4 (Scan-right + 0 four)) eos) (eq? (At 4 (Scan-right + 0 four four)) eos) (= (Length (Scan-right + 0 four four)) 4) (= (Length (Scan-left + 0 four four)) 4) (symbol? (At 4 (Scan-left + 0 four four))) (symbol? (At 10 (Scan-left + 0 four four))) (symbol? (At 20 (Scan-right + 0 four four))) (symbol? (At 4 (Take 10 four))) (equal? (Drop 2 five) '(2 3 4)) (= (First (Drop 3 integers)) 3) (List? (Drop 10 four)) (Null? (Drop 10 four)) (equal? (Drop-while even? five) '(1 2 3 4)) (equal? (Drop-until odd? five) '(1 2 3 4)) (equal? (BigList->list (Drop-while odd? (List 1 3 5 2 3 4))) '(2 3 4)) (equal? (BigList->list 5 (Drop-while even? integers)) '(1 2 3 4 5)) (not (List? (Drop 10 integers))) (equal? (BigList->list (Append four four)) '(0 1 2 3 0 1 2 3)) (equal? (BigList->list (Append four four four)) '(0 1 2 3 0 1 2 3 0 1 2 3)) (equal? (BigList->list (Reverse four)) '(3 2 1 0)) (equal? (Reverse four '()) '(3 2 1 0)) (equal? (Reverse five) '(4 3 2 1 0)) (equal? (BigList->list 10 (Reverse four integers)) '(3 2 1 0 0 1 2 3 4 5)) (equal? (BigList->list 5 (Map BigList->list (Reverse* integers))) '(() (0) (1 0) (2 1 0) (3 2 1 0))) (equal? (Reverse* five) '(() (0) (1 0) (2 1 0) (3 2 1 0) (4 3 2 1 0))) (equal? (BigList->list (Map BigList->list (Reverse* four))) '(() (0) (1 0) (2 1 0) (3 2 1 0))) (equal? (BigList->list (Zip four four)) '(0 0 1 1 2 2 3 3)) (equal? (Zip five five) '(0 0 1 1 2 2 3 3 4 4)) (equal? (BigList->list 12 (Zip four integers)) '(0 0 1 1 2 2 3 3 4 5 6 7)) (equal? (BigList->list 5 (Iterate add1 0)) '(0 1 2 3 4)) (equal? (BigList->list 5 (Repeat 0)) '(0 0 0 0 0)) (equal? (BigList->list 5 integers) '(0 1 2 3 4)) (equal? (BigList->list 10 (nth-value 0 (Unzip integers))) '(0 2 4 6 8 10 12 14 16 18)) (equal? (BigList->list 10 (nth-value 1 (Unzip integers))) '(1 3 5 7 9 11 13 15 17 19)) (equal? (BigList->list (nth-value 1 (Unzip four))) '(1 3)) (equal? (nth-value 0 (Unzip five)) '(0 2 4)) (equal? (nth-value 1 (Unzip five)) '(1 3)) (Some? odd? four) (Some? odd? five) (not ((Every? odd?) four)) (not ((Every? odd?) five)) (Sorted? <= four) (Sorted? <= five) (equal? (BigList->list (Merge <= four four)) '(0 0 1 1 2 2 3 3)) (equal? (Merge <= five five) '(0 0 1 1 2 2 3 3 4 4)) (equal? (Sort <= '(2 1 5 1 3 0)) '(0 1 1 2 3 5)) (equal? (BigList->list (Sort <= (Append four four))) '(0 0 1 1 2 2 3 3)) (equal? (BigList->list (Sort <= (List 5 3 2 7 5 1 0))) '(0 1 2 3 5 5 7)) (equal? (BigList->list (Sort < (List 5 3 2 7 5 1 0))) '(0 1 2 3 5 5 7)) (equal? (bind (x . xs) integers (list x (BigList->list 5 xs))) '(0 (1 2 3 4 5))) (equal? (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))) (equal? (BigList->list (Remp odd? four)) '(0 2)) (equal? (Remv 1 '(0 1 2 1 3 1 4)) '(0 2 3 4)) (equal? (BigList->list (Remv 1 four)) '(0 2 3)) (= (Index (cut = <> 5) integers) 5) (= (Index odd? four) 1) (= (Index (cut = <> 2) five) 2) (= (Index odd? five) 1) (equal? (BigList->list 10 (Memp odd? integers)) '(1 2 3 4 5 6 7 8 9 10)) (equal? (BigList->list 10 (Memv 3 integers)) '(3 4 5 6 7 8 9 10 11 12)) (not (Eqv? four (list 0 1 2 3))) (Eqv? four (List 0 1 2 3)) (Eqp? = four (List 0 1 2 3)) (equal? (list 0 1 2 3) (list 0 1 2 3)) (Equal? (list 0 1 2 3) (list 0 1 2 3)) (Equal? (List 0 1 2 3) (List 0 1 2 3)) (Eqp? = integers integers) (equal? (Assv 1 (List '(0 5) '(1 6) '(2 7))) '(1 6)) (equal? (Assv 1 '((0 5) (1 6) (2 7))) '(1 6)) (equal? (BigList->list (Assv 2 (List (List 0 5) (List 1 6) (List 2 7)))) '(2 7)) (equal? (BigList->list (Assp odd? (List (list 0 5) (list 1 6) (list 2 7)))) '(1 6)) (equal? (BigList->list (Assp odd? (List (List 0 5) (List 1 6) (List 2 7)))) '(1 6)) (equal? (Assp (cut eq? <> 'b) '((a A) (b B) (c C))) '(b B)) (equal? (Assq 'b '((a A) (b B) (c C))) '(b B)) (not (Assq 'x '((a A) (b B) (c C)))) (equal? (BigList->list 5 (Range #f)) '(0 1 2 3 4)) (equal? (BigList->list 5 (Range 0 #f)) '(0 1 2 3 4)) (equal? (BigList->list 5 (Range 0 #f -2)) '(0 -2 -4 -6 -8)) (not (List? (Range 0 #f 1))) (not (List? (Range 0 #f))) (equal? (BigList->list 4 (Range 0 5 1)) '(0 1 2 3)) (equal? (BigList->list (Range 0 5 1)) '(0 1 2 3 4)) (equal? (BigList->list (Range 5 0 -1)) '(5 4 3 2 1)) (equal? (BigList->list (Range 0 -1)) '(0)) (equal? (BigList->list (Iterate-while sub1 positive? 5)) '(5 4 3 2 1)) (equal? (BigList->list (Iterate-times add1 5 1)) '(1 2 3 4 5)) (Print five) (equal? (BigList->list (For ((x four)) (add1 x))) '(1 2 3 4)); map (equal? (BigList->list (For ((x (List 0 1 2 3 4 5 6) (odd? x))) x)) ; filter '(1 3 5)) (equal? (BigList->list (For ((n (List 0 1 2 3 4 5 6) (positive? n) (even? n))) (* 10 n))) '(20 40 60)) (equal? (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))) (equal? (BigList->list (For ((c (List 'A 'B 'C)) ;lazy (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))) (equal? (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))) (equal? (For ((c '(A B C)) ;eager (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))) ) (compound-test (BIGLISTS) (biglists?) )