PLQ #7Done on:   Tuesday, November 8th

Question 1 @ 2022-11-08 18:49

Say that we enter the following in the Racket REPL:

> (define x (box 'red))
> (define y (box 'green))
> (set-box! x (set-box! y 'blue))
> (unbox x)

What is the result of the last expression?


R. ’red G. ’green B. ’blue V. # E. Type Error L. Infinite loop

Question 2 @ 2022-11-08 18:56

Say that you’re working in a REPL of a Racket-like language, and you have a box value in x: (define x (box 1)) Consider the following expression: (list (set-box! x (add1 (unbox x))) (unbox x)) Based on the result of this expression, you’ll be able to tell whether the language:


  1. … evaluates left-to-right or right-to-left.

  2. … is eager or lazy.

  3. … uses lexical scope or dynamic scope.

  4. … returns the new value, the old value, or some useless value as a result of varaible assignment.

  5. … returns the new value, the old value, or some useless value as a result of a box mutation.

  6. … is statically typed or not.

Question 3 @ 2022-11-08 19:01

In our new Toy Language what does this return?

{bind {{+ *}} {+ 4 5}}

  1. 9
  2. 20
  3. Error – lookup: no binding for *
  4. Error: Unable to overwrite operators
  5. Bad syntax error

Question 4 @ 2022-11-08 19:05

Say that you have two types defined:

(define-type Sub  = Boolean)
(define-type Super = (U String Boolean))

Which of the following is true:


  1. (Listof Sub) subtype-of (Listof Super)

  2. (Listof Super) subtype-of (Listof Sub)

  3. T -> Sub subtype-of T -> Super

  4. T -> Super subtype-of T -> Sub

  5. Sub -> T subtype-of Super -> T

  6. Super -> T subtype-of Sub -> T

  7. Sub -> Sub subtype-of Super -> Super

  8. Super -> Super subtype-of Sub -> Sub

  9. (Boxof Sub) subtype-of (Boxof Super)

  10. (Boxof Super) subtype-of (Boxof Sub)