> (run '((lambda (x) x) 1)) 1 > (run '((lambda (x) (x 1)) (lambda (x) x))) 1 > (run '(((lambda (x) (lambda (y) (+ x y))) 1) 2)) 3
> (run '(let ((a 1)) (+ a 1))) 2 > (run '(let ((a 1)) (let ((b 2) (a 4)) (+ a b)))) 6
(lambda (v ...) e0 e1 ...)
-->
(lambda (v ...) (begin e0 e1 ...))
> (run '(begin 10)) 10 > (run '(begin (+ 3 4) 10)) 10 > (run '(begin (+ 3 4) (+ 4 5) 10)) 10 > (run '((lambda () (+ 3 4) 10))) 10
set! expression: In the examples
below, set! returns the symbol
unspecified.
> (run '(let ((a 1)) (set! a 5)))
unspecified
> (run '(let ((a 1)) (begin (set! a 10) (+ a 10))))
20
> (run '(let ((x 3))
(let ((f (lambda () (set! x (add1 x)) 9)))
(begin (f) (f) x))))
5
> (run '(define x 3))
unspecified
> (run '(+ x 1))
4
> (run '(define x 5))
unspecified
> (run 'x)
5
> (run '(begin (set! x 6) x))
6
> (run '(define even
(lambda (n)
(if (zero n)
1
(odd (sub1 n))))))
unspecified
> (run '(define odd
(lambda (n)
(if (zero n)
0
(even (sub1 n))))))
unspecified
> (run '(even 6))
1
Write your answers to the exercises in a file (with comments, following the proper indentation rules), and send that file to
c311@lakshmi.cs.indiana.eduwith the subject line
5Assuming you've saved your homework in the file ``asgn.ss'' in the current directory, one way to submit is with the command:
Mail -s "5" c311@lakshmi.cs.indiana.edu < asgn.ssIf you use the
define-record stuff, include the expression
(load "record.ss")in your submission.
Back to the c311 page
ehilsdal@cs.indiana.edu