Question 1 @ 2023-02-14 18:08
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))
Answers: 2, 6, 7, 10, 12
Question 2 @ 2023-02-14 18:13
Which of the following is an advantage of having a dynamically scoped
language?
- Being able to know in advance exactly what a function will do
- Use values before they are defined
- Simple recursion
- “Remote” customization of code you don’t own
- Faster runtime due to compilation
Question 3 @ 2023-02-14 18:23
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}}}}}
- Syntax error
- Runtime error
Question 4 @ 2023-02-14 18:28
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}}}}}
- Syntax error
- Runtime error
Question 5 @ 2023-02-14 18:29
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}}}}}
- Syntax error
- Runtime error
Question 6 @ 2023-02-14 18:32
Is it possible for a single language to implement both lexical and
dynamic scope at the same time?
(Choose the best answer!)
- Impossible.
- It’s impossible to mix the two, since dynamic scope kills reasoning.
- As we’ve seen in class, the evaluator must make a choice of either
dynamic or lexical scope, so implementing both is impossible.
- As we’ve seen in class, it is not only possible, but there is one
language that implement both.
- As we’ve seen in class, it is not only possible, but there are
several languages that implement both.