Question 1 @ 2025-03-25 18:23
What should the following expression evaluate to in the #lang pl lazy
REPL?
(if (loop) "foo" x)
-
"foo"
-
Error: Unbound identifier
x
- Infinite loop
- Stack overflow
- Runtime error
- Syntax error
Question 2 @ 2025-03-25 18:27
What should the following expression evaluate to in the #lang pl lazy
REPL?
(if (list (loop)) "foo" x)
-
"foo"
-
Error: Unbound identifier
x
- Infinite loop
- Stack overflow
- Runtime error
- Syntax error
Question 3 @ 2025-03-25 18:29
When we talked about the implementation of our Sloth lazy language, we’ve talked about a need for a function that “forces lazy values”:
(define (strict val)
(cases val
[(ExprV expr env) (strict (eval expr env))] ; loop back
[else val]))
When is this function always needed?
-
In the toplevel
run
function -
Checking the boolean in an
if
expression -
Returning a result from an
if
expression -
When we
bind
a value (i.e, for the named expression) - To get the value of a function
- To get the value of a function call
- To get function argument values
Question 4 @ 2025-03-25 18:33
When we talked about the implementation of our Sloth lazy language, we’ve talked about a need for a function that “forces lazy values”:
(define (strict val)
(cases val
[(ExprV expr env) (strict (eval expr env))] ; loop back
[else val]))
When is this function sometimes needed?
-
In the toplevel
run
function -
Checking the boolean in an
if
expression -
Returning a result from an
if
expression -
When we
bind
a value (i.e, for the named expression) - To get the value of a function
- To get the value of a function call
- To get function argument values
Question 5 @ 2025-03-25 18:35
(Warning: possibly difficult question.)
In our Sloth implementation, we implemented if
as a builtin part of
out evaluator:
(eval* ...)]
We’ve also seen that in #lang pl lazy
, if
is a function (unlike
Racket, where if
is a special form).
The question is: must if
be provided as a builtin functionality in the
language?
-
No: we’ve seen that it can be a function, even a user-defined one
-
It must be a builtin to use
strict
in the right place -
It can be implemented as a builtin
PrimV
function -
It has to be a builtin, as we did above