PLQ #9Done on:   Tuesday, March 18th

Question 1 @ 2025-03-18 18:26

Consider the following optimization from the class notes:

(define (foo list)
  (map (lambda (n) (if E0 E1 E2))
      list))
;; -->
(define (foo list)
  (map (if E0
        (lambda (n) E1)
        (lambda (n) E2))
      list))

What is an expression examples for E0 for which this would be a valid transformation?


Question 2 @ 2025-03-18 18:28

Still considering the same optimization:

(define (foo list)
  (map (lambda (n) (if E0 E1 E2))
      list))
;; -->
(define (foo list)
  (map (if E0
        (lambda (n) E1)
        (lambda (n) E2))
      list))

What are the required conditions to make this a good transformation?


Question 3 @ 2025-03-18 18:31

We’ve talked about the Toy language that we’re now using. Consider the following code in this language:

{bind {{+ *}
      {* +}}
  {* {+ 1 10} 100}}

What would this evaluate to?


Question 4 @ 2025-03-18 18:33

Continuing with our new toy — the Toy language — extended with a set! and multi-body-expressions as done in the HW. What would the following produce?

{bind {{* *}}
  {set! + -}
  {set! * -}
  {* 100 {+ 10 1}}}

What would this evaluate to?


Question 5 @ 2025-03-18 18:36

Suppose we run more code after we ran the previous example:

(run "{bind {{* *}}
        {set! + -}
        {set! * -}
        {* 100 {+ 10 1}}}")
(list (run "{+ 10 2}") (run "{* 10 2}"))

What would the above return?