Quiz 7
This quiz is due Wednesday, September 26, 2012, at 10 AM Eastern Time.
Sign in to Google to save your progress. Learn more
Enter your course pin: *
The following definitions are for question 1 (more or less copied from the notes):
;; Program 1
(define (msg1 o m a)
  ((o m) a))

(define (o-constr-1 x)
  (lambda (m)
    (case m
      [(addX) (lambda (y) (+ x y))])))
 
(test (msg1 (o-constr-1 5) 'addX 3) 8)
(test (msg1 (o-constr-1 2) 'addX 3) 5)


;; Program 2
(define (msg0 o m)
  ((o m)))

(define o-static-1
  (let ([counter 0])
    (lambda (amount)
      (begin
        (set! counter (+ 1 counter))
        (lambda (m)
          (case m
            [(inc) (lambda (n) (set! amount (+ amount n)))]
            [(dec) (lambda (n) (set! amount (- amount n)))]
            [(get) (lambda () amount)]
            [(count) (lambda () counter)]))))))

(test (let ([o (o-static-1 1000)])
        (msg0 o 'count))
      1)
 
(test (let ([o (o-static-1 0)])
        (msg0 o 'count))
      2)


;; Program 3
(define (msg/self o m a)
  ((o m) o a))

(define o-self-no!
  (lambda (m)
    (case m
      [(first) (lambda (self x) (msg/self self 'second (+ x 1)))]
      [(second) (lambda (self x) (+ x 1))])))

(test (msg/self o-self-no! 'first 5) 7)

Q!: Which of the above programs don't type check in plai-typed?  Choose ALL that apply. *
Required
Q2: In o-static-1, if we swap the second line (with let), and the third line (with lambda), will the created objects' behavior change? *
Q3: In o-self! (from the notes, but not shown above), could we have used boxes instead of variables? *
Q4: Does dynamic dispatch depend on the existence of classes? *
Submit
Clear form
Never submit passwords through Google Forms.
This content is neither created nor endorsed by Google. - Terms of Service - Privacy Policy

Does this form look suspicious? Report