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))
(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?
- 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 @ 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}}}}}
{with {foo {fun {x} {* x x}}}
{call foo {with {x 2}
{call foo x}}}}}
- Syntax error
- Runtime error
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}}}}}
{with {foo {fun {x} {* x x}}}
{call foo {with {x 2}
{call foo x}}}}}
- Syntax error
- Runtime error
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}}}}}
{with {foo {fun {x} {* x x}}}
{call foo {with {x 2}
{call foo x}}}}}
- Syntax error
- Runtime error
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!)
- 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.