A scoring program evaluates if check() then fast() + 6 else slow() + 6 using a selective conditional and strict addition. For this run, check() returns false and takes 2 ms; fast() returns 9 and would take 4 ms; slow() returns 14 and takes 11 ms. Calls execute sequentially. Ignore all other costs. Find the returned score, an integer, and the evaluation time in ms. Give both answers to zero decimal places.
Unlock full course notes by signing up
Required operands and unreachable errors
An evaluator uses selective conditionals and strict left-to-right addition. Calling fail() immediately raises an error and stops evaluation. Each case below is evaluated independently:
Case A: if true then 12 else fail().
Case B: 12 + fail().
Vocabulary of evaluation strategies
Match each term used to describe how a programming language evaluates expressions with the description that defines it.
Counting calls under two reduction orders
A function slow(n) takes 30 ms and returns 2 * n; every other operation takes negligible time. Two more functions are defined:
Consider the expression
Under applicative order, every argument is evaluated to a value before a function body runs. Under normal order, each argument expression is substituted unevaluated into the body and evaluated each time the body uses it. In both strategies *, + and the condition of if are strict.
When an algebraic shortcut changes termination
An evaluator has strict integer multiplication and selective conditionals. The expression spin() runs forever without returning a value or raising an error. Consider 0 * spin() and if true then 11 else spin(). Which statements correctly describe their behaviour or a proposed simplification? Select all that apply.