PLQ #5Done on:   Tuesday, February 13th

Question 1 @ 2024-02-13 18:28

Assuming a correct FLANG substitution, what will the following substitution result in?

{call {fun {x} {+ x 1}} {+ x 2}}[3/x]

Question 2 @ 2024-02-13 18:32

In the properly dynamically scoped language that we discussed in class, what would the following code evaluate to?

#lang ... dynamic

(define y 1)
(define (f x) (+ x y))
(let ([x 2]
      [y 3]
      [+ -])
  (f 4))

Question 3 @ 2024-02-13 18:36

In the properly dynamically scoped language that we discussed in class, what would the following code evaluate to?

#lang ... dynamic

(define x 1)
(define y 2)
(let ([x 11]
      [y 22])
  (let ([x y]
        [y x])
    (list x y)))

Question 4 @ 2024-02-13 18:39

What will the following return, assuming the current FLANG-ENV code in class?

(The Flang language, implemented with environments)

(eval (parse "{with {x 5}
                {fun {y} {+ y x}}}")
      (EmptyEnv))

Question 5 @ 2024-02-13 18:44

Which of the following advantages of dynamic scope is correct?


Question 6 @ 2024-02-13 18:46

Reflecting on the Fun and Call expressions’ evaluation strategy, why is the substitution cache crucial for implementing closures in a language that supports first-class functions?