Lab Quiz Solutions, Foundations of Computing, Week 4 -- Oct 17, 2000

Given these definitions:

(define x 1)

(define (add-x y)
  (+ x y))

(define (dbl-x x)
  (+ x x))

(define (add-sum y)
  (let ((sum (add-x x)))
    (+ sum y)))

(define (add-list y)
  (every add-x y))

For each of the following expressions, if the expression can be evaluated, write its value. If the expression cannot be evaluated, explain why not.

  1. 1
    1

  2. x
    1

  3. 'x
    x

  4. y
    Can't evaluate, not defined

  5. 'y
    y

  6. (x)
    Can't evaluate, 1 is not a procedure

  7. '(x)
    (x)

  8. ('x)
    Can't evaluate, x is not a procedure

  9. (add-x 1)
    2

  10. (add-x x)
    2

  11. (add-x 'x)
    Can't evaluate, x is not a number

  12. (dbl-x 1)
    2

  13. (dbl-x x)
    2 -- Here x is global, bound to 1

  14. (dbl-x 2)
    4 -- Here 2 is bound to the local x

  15. (add-sum 1)
    3

  16. (add-list (1 2 3))
    Can't evaluate, 1 is not a procedure

  17. (add-list '(1 2 3))
    (2 3 4)

  18. (add-x '(1 2 3))
    Can't evaluate, (1 2 3) is not a number

  19. (keep even? (add-list '(1 2 3)))
    (2 4)