Match each term used to describe how a programming language evaluates expressions with the description that defines it.
Every argument is reduced to a value before the function body runs
The leftmost, outermost reducible expression is reduced first, so arguments enter the body unevaluated
Can return a defined result even when one of its arguments would loop forever if evaluated
A boolean operator skips its second operand when the first already fixes the result
A computation that never produces a value, such as an infinite loop
The sequence in which the operands of an operation are computed, for example left to right
Its result is undefined whenever a particular argument's evaluation fails or never finishes
Applicative order
Evaluation order
Normal order
Strict function
Non-strict function
Divergence
Short-circuit evaluation
Unlock full course notes by signing up
Timing the selected scoring path
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.
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().
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.