PLQ #5Done on:   Tuesday, October 15th

Question 1 @ 2024-10-15 18:44

Using our Racket-like dynamically-scoped language, what would the following evaluate to?

#lang pl dynamic
(define (add1 x) (+ x 1))
(define (mul y z) (* y z))
(let ([+ -] [* +])
  (mul (add1 5) 2))

2, 6, 7, 10, 12

Question 2 @ 2024-10-15 18:48

Which of the following is an advantage of having a dynamically scoped language?


Question 3 @ 2024-10-15 18:50

What is the result of running the following expression in the substitution-based FLANG evaluator?

{with {x 1}
  {with {foo {fun {x} {* x x}}}
    {call foo {with {x 2}
                {call foo x}}}}}

Question 4 @ 2024-10-15 18:52

What is the result of running the following expression in the environment-based FLANG evaluator?

{with {x 1}
  {with {foo {fun {x} {* x x}}}
    {call foo {with {x 2}
                {call foo x}}}}}

Question 5 @ 2024-10-15 18:54

What is the result of running the following expression in the broken dynamically-scoped FLANG evaluator?

{with {x 1}
  {with {foo {fun {x} {* x x}}}
    {call foo {with {x 2}
                {call foo x}}}}}

Question 6 @ 2024-10-15 18:56

Is it possible for a single language to implement both lexical and dynamic scope at the same time?

(Choose the best answer!)