Question 1 @ 2024-03-26 18:23
Which of the following tools did we use to implement our lazy language?
- Thunks
- Generators
- Macros
- Expression closures
- Tail call optimization
- Conditional evaluation
Question 2 @ 2024-03-26 18:28
If the following code is executed in our Lazy Racket language, what is the result? (In this example «E₁» and «E₂» are placeholders for some expression.)
11
12)
- 11
- 12
- An error; the program crashes with a division by zero
- An error; the program crashes because a list is given as the condition of ‘if’
- Cannot answer this without knowing what is «E₁».
- Cannot answer this without knowing what is «E₂».
Question 3 @ 2024-03-26 18:33
What problem in our Sloth implementation does the strict
function
solve?
- It allows constructing infinite lists.
- It enables infinite loops.
-
It ensures that only
RktV
s are returned from theeval*
function. -
It handles cases where evaluating an
ExprV
results in anExprV
. -
It creates a new closure of an
ExprV
and a given environment. - Strict does not solve any particular problem, it makes the code run more efficiently.
- Strict does not solve any particular problem, it’s just a convenience function.
Question 4 @ 2024-03-26 18:36
As we’ve seen last week, generators and channels give programmers more expressive control flow constructs. Which of the following statements explains why this works?
- They use call-by-reference to delay evaluation.
- They can be used to implement control flows that are different from the standard call-a-function-and-get-an-answer.
- They provide a better implementation of short-circuit evaluations.
- They are eagerly evaluated when called.
- They cannot be partially evaluated.
Question 5 @ 2024-03-26 18:38
Consider the following type definition for VAL
from our lazy Sloth
evaluator:
[RktV Any]
[FunV (Listof Symbol) SLOTH ENV]
[ExprV SLOTH ENV (Boxof (U #f VAL))]
[PrimV ((Listof VAL) -> VAL)])
Is this from the version of Sloth that implements a call by name or call by need language?
Choose the best answer.
-
Call by name, because we look up the value of each
ExprV
in the environment using its name. -
Call by name, because the value of each
ExprV
is recalculated every time it is evaluated. -
Call by need, because the value of each
ExprV
is cached after the first time it is evaluated. -
Call by need, because
strict
is only called on anExprV
when we need to force it into a proper value. -
Impossible to tell, since the type definition is the same for both, only the implementation is different.