Now let's test a few in-class examples:
1 ]=> 1
;Value: 1
1 ]=> #t
;Value: #t
1 ]=> coffee
;Unbound variable: coffee
;To continue, call RESTART with an option number:
; (RESTART 3) => Specify a value to use instead of coffee.
; (RESTART 2) => Define coffee to a given value.
; (RESTART 1) => Return to read-eval-print level 1.
Oh Well...I was hoping for some french roast...
2 error>
;Quit!
1 ]=> (+ 1 2)
;Value: 3
1 ]=> (* 3 4)
;Value: 12
It's worth noting that these functions can take more
than two arguments:
1 ]=> (+ 1 2 3 4 5)
;Value: 15
1 ]=> (define pi 3.14)
;Value: pi
1 ]=> pi
;Value: 3.14
1 ]=> (define radius 2)
;Value: radius
1 ]=> (define circ (* 2 pi radius))
;Value: circ
1 ]=> circ
;Value: 12.56
1 ]=> (define radius 3)
;Value: radius
1 ]=> circ
;Value: 12.56636
What went wrong here?
Obviously, just like Harry's "n" example yesterday, circ evaluates to a number, not to an expression.
How do I fix it?
1 ]=> (define (circ) (* 2 pi radius))
;Value: circ
You'll learn Monday that those subtle parentheses are just "syntactic sugar" for:
1 ]=> (define circ (lambda () (* 2 pi radius)))
;Value: circ
1 ]=> (circ)
;Value: 18.849539999999998
1 ]=> (define radius 5)
;Value: radius
1 ]=> (circ)
;Value: 31.4159
And now finally to load the file for Problem Set 1:
1 ]=> (load "lunar.scm")
;Loading "lunar.scm" -- done
;Value: sixth