$ scheme48 > ,load ex2-sum-square-smaller-two.scm > > (sum-of-square-smaller-two 1 2 3) 5 > (sum-of-square-smaller-two 1 2 -3) 10 > (sum-of-square-smaller-two 2 2 2) 8 > ,exit $
$ scheme48 > ,load ex3-cube-root.scm > (cube-root 1331) 11.0 > (cube-root 512) 8.0 > ,exit $
$ scheme48 > ,load ex4.scm > (fun-rec 0) 7 > (fun-rec 5) -3 > (fun-rec 10) 51 > (fun-ite 10) 51 > (fun-ite 100) 84553538310603107 > (fun-rec 100) <------------- take too much time to run ^C interrupt: keyboard interrupt [command-level-event-handler] keyboard 1> ,exit $
$ $ cat ex5.scm (define (expmod b n m) (define (*mod a b) . . . . ) (define (square x) . . . . ) (define (iter res b n) . . . ) (iter 1 b n)) $ $ scheme48 > ,load ex5.scm > > (expmod 3 1000 123) 42 > (expmod 3 0 123) 1 > (expmod 3 101 10) 3 > (expmod 123232 11123232322 1123) 256 > ,exit $
$ scheme48 > ,load ex6.scm > > (define (ok k) #t) ;; always true ; no values returned > (define (inc x) (+ x 1)) ; no values returned > (define (id x) x) ; no values returned > (filtered-accumulate ok + 0 id 1 inc 10) 55 > (filtered-accumulate ok * 1 id 1 inc 10) 3628800 > (filtered-accumulate even? + 0 id 1 inc 10) 30 > (sum-divisors 10) 18 > (sum-divisors 1) 1 > (sum-divisors 120) 360 > ,exit $
$ scheme48 > ,load ex7.scm > (+ 1.0 (cont-frac (lambda (i) 1.0) (lambda (i) 1.0) 1000)) 1.618033988749895 > > (root 5) 2.7912878474779195 > (root 0) 1.0 > (root 1) 1.618033988749895 > ,exit $
$ scheme48 > ,load ex8-pair-int.scm > (define x (my-cons 2 -5)) ; no values returned > (my-car x) 2 > (my-cdr x) -5 > ,exit $
$ scheme48 > ,load ex9-select.scm > (select (lambda (x y) (= x y)) 10 1 2 3 10 20 10) (10 10) > (select (lambda (x y) (even? y)) 10 1 2 3 4 5 6 7 8) (2 4 6 8) > (select (lambda (x y) (even? (+ x y))) 4 1 2 3 4 5 6 7 8 9 10 11) (2 4 6 8 10) > (same-parity 4 1 2 3 4 5 6 7 8 9 10 11) (4 2 4 6 8 10) > (select (lambda (x y) (even? (+ x y))) 3 1 2 3 4 5 6 7 8 9 10 11) (1 3 5 7 9 11) > (same-parity 3 1 2 3 4 5 6 7 8 9 10 11) (3 1 3 5 7 9 11) > (same-parity 1) (1) > ; ; (apply f L), apply f with argument list L, ; for example: (apply + (list 7 9 11)) ==> (+ 7 9 11) ; If `f' can accept variable number of arguments, `apply' is a must ; since it is impossible to invoke f like (f 1 2) and (f a b c d) ; simultaneously in a program. ; > (apply + (list 1 2 3)) ; the same as (+ 1 2 3) 6 > (apply + (cons 1 (cons 2 (list 7 9)))) ; the same as (+ 1 2 7 9) 19 > (apply select ; the same as the first example (cons (lambda (x y) (= x y)) (cons 10 (list 1 2 3 10 20 10)))) (10 10) > ,exit
a / | \ ==> (a (b) (c) (d)) b c d a / | \ ==> (a (b) (c (e)) (d (f) (g))) b c d | |\ e f g
$ scheme48 > ,load ex10-preorder.scm > > (preorder '(a (b (c)) (e (f) (g)))) (a b c e f g) > > (preorder '(a (b) (c) (f (g) (h)))) (a b c f g h) > > (preorder '((hello) (b) ((baga me) (ok)))) ((hello) b (baga me) ok) > ,exit $
$ scheme48 > ,load ex11-enum-tuples-row-major.scm > (enum-tuples) () > (enum-tuples '(a b c)) ((a) (b) (c)) > (enum-tuples '(a b c) '(11 22)) ((a 11) (a 22) (b 11) (b 22) (c 11) (c 22)) > (enum-tuples '(a b) '(1 2) '(ok no)) ((a 1 ok) (a 1 no) (a 2 ok) (a 2 no) (b 1 ok) (b 1 no) (b 2 ok) (b 2 no)) > (enum-tuples '(a b) '(yes) '(ok no) '(aloha hi)) ((a yes ok aloha) (a yes ok hi) (a yes no aloha) (a yes no hi) (b yes ok aloha) (b yes ok hi) (b yes no aloha) (b yes no hi)) > ,exit $
$ scheme48 > ,load ex12-deriv.scm > (deriv '(+ x y) 'y) 1 > (deriv '(* x y) 'x) y > (deriv '(** (+ x y) 9) 'x) (* 9 (** (+ x y) 8)) > (deriv '(** (+ x y) 1) 'y) 1 > (deriv '(** (+ x y) 2) 'y) (* 2 (+ x y)) > (deriv '(** (* x y) 3) 'x) (* (* y 3) (** (* x y) 2)) > ,exit $
$ scheme48 > ,open random > (define a (make-random 1024)) ; no values returned > (a) 150946159 > (a) 44350967 > ,load ex13-monitor.scm > (define f (make-monitored a)) ; no values returned > (f) 88941411 > (f) 154130900 > (f 'how-many-calls?) 2 > (f) 1024 > (f) 159857230 > (f) 53732961 > (f 'how-many-calls?) 5 > (f 'reset-count) 0 > (f) 10059006 > (f 'how-many-calls?) 1 > (define plus (make-monitored +)) ; no values returned > (plus) 0 > (plus 1 2 3 4 5) 15 > (plus 'how-many-calls?) 2 > (plus 'reset-count) 0 > (plus 1 2) 3 > (plus 'how-many-calls?) 1 > ,exit $