home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-07-26 | 5.6 KB | 213 lines | [TEXT/gamI] |
- MacGambit v2.0
- --------------
-
- * The documentation is now available through the online help system (in the
- apple menu).
-
- * Check the "Examples" folder for Scheme code examples and demos.
-
- * Here is a transcript of a typical interaction with MacGambit (comments are
- marked with ";;;"):
-
-
- MacGambit (v2.0)
-
- : (define (fact x)
- (cond ((= x 0) 1)
- ((= x 1) 1)
- ((> x 1) (* (fact (- x 1)) x))
- (else (error "argument must be positive"))))
- fact
-
- : (trace fact) ;;; let's check what fact is doing
- fact
-
- : (fact 10)
- Entry (fact 10)
- |Entry (fact 9)
- | Entry (fact 8)
- | Entry (fact 7)
- | |Entry (fact 6)
- | | Entry (fact 5)
- | | Entry (fact 4)
- | | |Entry (fact 3)
- | | | Entry (fact 2)
- | | | Entry (fact 1)
- | | | ==> 1
- | | | ==> 2
- | | |==> 6
- | | ==> 24
- | | ==> 120
- | |==> 720
- | ==> 5040
- | ==> 40320
- |==> 362880
- ==> 3628800
- 3628800
-
- : (untrace fact) ;;; remove tracing of fact
- fact
-
- : (let ((x (runtime))) (let ((y (fact 50))) (cons (- (runtime) x) y)))
- (.02 . 30414093201713378043612608166064768844377641568960512000000000000)
-
- : (pp fact)
- (lambda (x)
- (cond ((= x 0) 1)
- ((= x 1) 1)
- ((> x 1) (* (fact (- x 1)) x))
- (else (error "argument must be positive"))))
- #f
-
- : (define f fact) ;;; save value of fact in f
- f
-
- : (define fact "not the factorial function")
- fact
-
- : (f 5)
- *** ERROR IN f -- Operator is not a PROCEDURE
- (fact (- x 1))
-
- 1: ;;; typed: <cmd>-B
- 0 f (fact (- x 1))
- -1 (top level) (f 5)
- -2 ##dynamic-env-bind
- -3 ##read-eval-print
- -4 ##dynamic-env-bind
- -5 ###_kernel.startup
-
- 1: ;;; typed: <cmd>-I
- #[procedure f] =
- (lambda (x)
- (cond ((= x 0) 1)
- ((= x 1) 1)
- ((> x 1) (* (fact (- x 1)) x))
- (else (error "argument must be positive"))))
-
- 1: ;;; typed: <cmd>-L
- x = 5
-
- 1: (- x 1) ;;; we can use x and it will refer to the local x (f's argument)
- 4
-
- 1: fact ;;; check value of fact
- "not the factorial function"
-
- 1: (set! fact f)
- #[undefined]
-
- 1: ;;; typed: <cmd>-R (we want to resume from the error)
- Return value: (fact (- x 1)) ;;; this is the value to return
- 120
-
- : (list (gensym) (gensym) (gensym))
- (g1 g2 g3)
-
- : (put 'bob 'eyes 'blue)
- #f
-
- : (put 'mary 'hair 'blond)
- #f
-
- : (get 'bob 'eyes)
- blue
-
- : (get 'mary 'eyes)
- #f
-
- : (define (series term) ;;; Concurrency is expressed with FUTUREs
- (let ((sum 0) (stop #f)) ;;; as is done in Multilisp
- (FUTURE (let loop ((i 0))
- (if (not stop)
- (begin (set! sum (+ sum (term i))) (loop (+ i 1))))))
- (lambda (msg)
- (cond ((eq? msg 'value) sum)
- ((eq? msg 'stop) (set! stop #t))
- (else (error "unknown message" msg))))))
- series
-
- : (define pi ;;; start a task to compute series expansion for pi
- (series (lambda (i) (/ 4. ((if (odd? i) - +) (+ (* i 2) 1))))))
- pi
-
- : (pi 'value) ;;; get current value of series
- 3.141419882340216
-
- : (pi 'value) ;;; again... it has changed!
- 3.1415194471477133
-
- : (pi 'value)
- 3.1416300745380195
-
- : (pi 'stop) ;;; now we kill the task
- #[undefined]
-
- : (pi 'value)
- 3.1415815090449892
-
- : (pi 'value)
- 3.1415815090449892
-
- : (load "pi") ;;; try computing pi another way...
- How many digits of pi do you want (0 to exit): 50
- 3.14159265358979323846264338327950288419716939937510
- How many digits of pi do you want (0 to exit): 0
- "pi.scm"
-
- : (queens 8 #t) ;;; Ooops, queens is not defined...
- *** ERROR -- Unbound variable: queens
-
- 1: ;;; typed: <cmd>-D
- : (load "queens") ;;; load it!
- "queens.O"
-
- : (queens 8 #t) ;;; try it out
- (4 2 7 3 6 8 5 1)
- (5 2 4 7 3 8 6 1)
- (3 6 4 2 8 5 7 1)
- (3 5 2 8 6 4 7 1)
- (5 7 1 3 8 6 4 2)
- (4 6 8 3 1 7 5 2) ;;; typed: <cmd>-. to interrupt computation
-
- *** INTERRUPT
-
- 1: ;;; typed: <cmd>-D
- : (load "tree")
- "tree.scm"
-
- : (tree-display (call-with-input-file "fact.scm" read))
- .
- .----------------------.
- . .
- define .-----------------------------.
- . .
- .---. .-----------------------------------.
- . . . .
- fact .--. .----------. ()
- . . . .
- n () if .----------------.
- . .
- .--. .-----------------.
- . . . .
- < .--. 1 .-----------------.
- . . . .
- n .--. .-------------. ()
- . . . .
- 2 () * .-----------.
- . .
- .-------. .--.
- . . . .
- fact .--------. n ()
- . .
- .--. ()
- . .
- - .--.
- . .
- n .--.
- . .
- 1 ()
- #[undefined]
-
- : ;;; typed: <cmd>-Q
-