Answers to Quiz 2

Problem 1 Solutions:
1A. (define args-of cdr)
or (define args-of (lambda (expr) (cdr expr)))

Grading system: worth 3
if you had (define args-of (cdr expr)) (in other words you forgot the 
					lambda --> 1 point).
If you forgot a parenth but the rest was correct --> 2 points.

1B (map (lambda (arg) (p-eval arg env)) exps) 

Grading: 4 points
if you wrote evaluate or lookup instead of p-eval you got 1 or 2 points.

1C (apply primitive-op vals)

Grading: worth 4 points
anything that showed that you were trying to apply primitive-ops to vals,
but was wrong still got 1 point.

1D and is a special form not a procedure. 
and is not a valid scheme expression; it has no value. 

> and
> Unbound variable: and

Grading: worth 4 points.
Partial creadit was to the discretion of the grader.

1E There were many ways to write this. Here is one
(define (and-proc arg . args)
  (if (null? args)
      (and arg (apply and-proc args))))

Grading system:
worth 10

If you had the correct test and base case for your approach, 2 points.
If you realized you had to cdr down args, but did not use apply on the
recursive call back (or a correct helper proc) you get 2 points.  If
you got the rest wrong but you either defined a helper or used apply
which would yield the correct recursive call back you got 5 points.
This is how partial credit was given on this part with one or two
points to the dicretion of the grader.

Problem 2 Solutions:
2A) The only expression which correctly update op-table is 5. Here is why:

  1. The expression updates ops, not op-table
  2. (cadr op-table) should be the list of vals. After evaluating
     this expression, (cadr op-table) will generate an error, and
     (cdr op-table), not (cadr op-table) contains the intended list
     of vals.
  3. Same problem as 2.
  4. Same problem as 2, and the additional problem that '(eq? and-proc)
     puts the symbols eq? and and-proc into the vals list. The goal
     is to put the procedures that eq? and and-proc evaluate to into 
     to vals list.
  5. Correctly updates op-table.
  6. Same problem as 2, and the additional problem that none of the 
     lists have the eq? procedure in the right place.
  7. Same problem as 2, and the additional problem that the intended
     vals list has only the and-proc procedure.

  The grading was 1 point for each correct answer, for a total of
  7 points possible on 2A.


  1. (set-car! vals val) 
     vars is a cons cell whose name is correct, vals is the corresponding
     cons cell in the vals-of list, so we need to set the car of vals
     to the correct new val. 

  2. (set-cdr! vars (list name))
     In this case, the name was not found in the environment, so we
     need to add the name to the end of the vars list. The above
     statement will do it. We also accepted expressions that used
     append! to put the list on the end of the name, and should
     accept expressions that put name on the front of the list, although
     I don't think we got any of those.

  3. (set-cdr! vals (list val))
     Same rationale as 2, except we are now adding the val to the end
     of the vals list.

  The grading was 4 points for each question, for a total of 12 points
  possible on 2B. No partial credit given.


  1. ((a b) (a c))
  2. (1 c)
  3. ((a c) (1 c))
  4. (1 ("LOOKUP: undefined var:"b))

  The grading was 1 point for 1 and 2, 2 points for 3 and 3, for a total
  of 6 points possible on 2B. 1 point partial credit given on 4 for any
  answer indicating an error.

Problem 3 Solutions:

Any of the following are correct for :

	'(? ? ~phrase)			; notice the quote
	'(?a ?b ~phrase)
	'(?a father ~phrase)
	'(my father ~phrase)