PLQ #5Done on:   Tuesday, February 11th

Question 1 @ 2025-02-11 18:40

Which of the following advantages of dynamic scope is correct?


Question 2 @ 2025-02-11 18:43

Which of the following features can be available in a dynamically-scoped language?


Question 3 @ 2025-02-11 18:45

Now that surely you know how lexical scope works, you know that

(let ([x 1] [y 2])
  (let ([y x] [x y])
    (list x y)))

evaluates to '(2 1).

What would we get if we try that in a dynamically scoped language?


Question 4 @ 2025-02-11 18:47

What would the following return when executed in our dynamically-scoped language?

(define (currify f)
  (lambda (x) (lambda (y) (f x y))))

(let ([x 3] [y 4])
  (((currify +) 1) 2))

3, 5, 7, Unbound-x, Unbound-y, Unbound-f, Infinite-loop

Question 5 @ 2025-02-11 18:50

What would the following return when executed in our dynamically-scoped language?

(define x 100)

(define (f x) (+ x 1))

(let ([f (lambda (x) (f x))])
  (f 5))

6, 101, Unbound-x, Unbound-f, Infinite-loop

Question 6 @ 2025-02-11 18:51

We’ve seen one way to implement a lookup function in a substitution cache:

(define (lookup name sc)
  (let ([cell (assq name sc)])
    ...))

Say that we change that by using

(assq name (reverse sc))

on the second line. Assuming this strategy (actually similar, since it’d need to handle multiple bindings on each level), what would we get for

(let ([x 1] [y 2])
  (let ([y x] [x y])
    (list x y)))

?