f(n) = n if n < 3 = f(n-1) - 2*f(n-3) otherwise
--prompt--> scheme48 > ,load ex6-filtered-accu.scm > > (filtered-accumulate * 1 identity 1 inc 10 odd?) 945 > (filtered-accumulate * 1 identity 1 inc 10 even?) 3840 > (prod-prime 5) 24 > (prod-prime 6) 5 > (prod-prime-mod 5) 4 > (prod-prime-mod 6) 5 > (prod-prime-mod 29) 28 > (prod-prime-mod 31) ;; if p is prime then (prod-prime-mod p) = p-1 30 > ,exit --prompt-->
--prompt--> scheme48 > ,load ex7-nth-root.scm > (nth-root (fast-expt 2 16) 8) 4.0 > (nth-root (fast-expt 2 32) 16) 4.0 > (nth-root (fast-expt 2 100) 50) 3.9999999986136436 > (nth-root (fast-expt 5 10) 10) 4.9999999992832524 > ,exit --prompt-->
$ scheme48 > ,load ex10-power-of.scm > > (define a (* (expt 2 14) (expt 3 6))) ; no values returned > a 11943936 > > (power-of a 2) 2 -- 1 -- () 4 -- 2 -- ((2 1)) 16 -- 4 -- ((4 2) (2 1)) 256 -- 8 -- ((16 4) (4 2) (2 1)) 65536 -- 16 -- ((256 8) (16 4) (4 2) (2 1)) 11943936 -- ((256 8) (16 4) (4 2) (2 1)) -- 0 46656 -- ((16 4) (4 2) (2 1)) -- 8 2916 -- ((4 2) (2 1)) -- 12 729 -- ((2 1)) -- 14 729 -- () -- 14 14 > > (power-of a 3) 3 -- 1 -- () 9 -- 2 -- ((3 1)) 81 -- 4 -- ((9 2) (3 1)) 6561 -- 8 -- ((81 4) (9 2) (3 1)) 11943936 -- ((81 4) (9 2) (3 1)) -- 0 147456 -- ((9 2) (3 1)) -- 4 16384 -- ((3 1)) -- 6 16384 -- () -- 6 6 > > (power-of a 7) 7 -- 1 -- () 11943936 -- () -- 0 0 > ,exit $
$ scheme48 > ,load ex11-enum-tuples.scm > > (enum-tuples) '() > (enum-tuples '(x y z)) '((x) (y) (z)) > (enum-tuples '(a b c) '(hello world)) '((a hello) (b hello) (c hello) (a world) (b world) (c world)) > (enum-tuples '(1 2) '(h i j k)) '((1 h) (2 h) (1 i) (2 i) (1 j) (2 j) (1 k) (2 k)) > ,exit $
$ scheme48 > ,load ex14-stream.scm > (define x (stream-enum-leaves '((1 2) (a (b)) (p (q (r)))))) ; no values returned > x '(1 . #{Procedure 1168 (unnamed in make-promise in scheme-level-1)}) > (stream-car x) 1 > (stream-ref x 2) 'a > (display-stream x) 1 2 a b p q r'done > ,exit $ $ cat ex14-stream.scm (define-syntax cons-stream (syntax-rules () ((cons-stream a b) (cons a (delay b))))) (define (stream-car s) (car s)) (define (stream-cdr s) (force (cdr s))) (define the-empty-stream 'empty-stream) (define (stream-null? s) (eq? s the-empty-stream)) (define (stream-ref s n) ..... (define (stream-enumerate-interval low high) .... (define (stream-for-each proc s) .... (define (display-stream s) ..... (define (stream-filter pred stream) .... (define (stream-enum-leaves T) ...... $