CSE 340 EXAM 2 QUESTIONS WITH
ANSWERS AND EXPLANATIONS
Question 1. Which test most directly verifies correct implementation of Evaluation order?
A. Construct side-effecting arguments and verify observed behavior against the documented sequencing rules.
B. Attempt the conversion with and without the explicit syntax and verify only the requested form is accepted.
C. Use a second operand with an observable side effect and verify it is skipped when the first operand determines the
result.
D. Trace the expression followed by a read of the mutated state and verify both value and effect.
Correct Answer: A. Construct side-effecting arguments and verify observed behavior against the documented
sequencing rules.
Explanation: Construct side-effecting arguments and verify observed behavior against the documented sequencing rules. This
directly validates Evaluation order; the alternatives test different language properties.
Question 2. Consider this type/runtime requirement: Programmers should omit many type annotations
while the compiler still determines consistent types. What is the most appropriate language mechanism?
A. Treat types as equivalent only when the language says their names or declared identities correspond.
B. Generate type constraints from program structure and solve them to infer missing types.
C. Associate type information with runtime values and check operations during execution.
D. Perform type checking at compile/analysis time using declared or inferred types.
Correct Answer: B. Generate type constraints from program structure and solve them to infer missing types.
Explanation: Generate type constraints from program structure and solve them to infer missing types. Concise source code
can retain static type guarantees without requiring annotations everywhere.
Question 3. Engineers diagnose the following semantic weakness: Always evaluate both operands before
determining the Boolean result. Which named mechanism is the clearest correction?
A. Evaluation order
B. Implicit coercion
C. Explicit conversion
D. Short-circuit evaluation
Correct Answer: D. Short-circuit evaluation
Explanation: Short-circuit evaluation is the direct match. Use short-circuit semantics for the Boolean operator.
Question 4. When A recursive call occurs in tail position and the implementation wants to avoid
unbounded stack growth., what is the main value of Tail-call optimization?
A. Tail-recursive computations can execute with constant or bounded stack space.
B. Nonlocal lexical bindings can be reached even when the dynamic caller is different.
C. The function retains correct lexical bindings even after the defining activation would otherwise be gone.
D. The runtime can unwind the dynamic call chain correctly on return.
Correct Answer: A. Tail-recursive computations can execute with constant or bounded stack space.
Explanation: Tail-recursive computations can execute with constant or bounded stack space. This is the central value of
Tail-call optimization in the stated situation.
,Question 5. Engineers diagnose the following semantic weakness: Reinterpret the integer bit pattern as a
floating-point value without conversion. Which named mechanism is the clearest correction?
A. Short-circuit evaluation
B. Expression side effects
C. Implicit coercion
D. Explicit conversion
Correct Answer: C. Implicit coercion
Explanation: Implicit coercion is the direct match. Apply the language-defined implicit conversion before performing the
mixed-type operation.
Question 6. Which experiment best validates Static typing rather than a neighboring concept?
A. Unify a set of compatible constraints and then add one conflicting constraint to verify failure is detected.
B. Infer the type of a small expression with no explicit annotations and verify all uses are consistent.
C. Declare structurally identical named types and verify the type checker still distinguishes them.
D. Compile a deliberately ill-typed program and verify it is rejected before execution.
Correct Answer: D. Compile a deliberately ill-typed program and verify it is rejected before execution.
Explanation: Compile a deliberately ill-typed program and verify it is rejected before execution. This directly validates Static
typing; the alternatives test different language properties.
Question 7. A language uses Closure because A function value escapes the scope where it was created
but must still access variables from that lexical environment later. Which benefit most strongly supports
that decision?
A. The runtime can unwind the dynamic call chain correctly on return.
B. Tail-recursive computations can execute with constant or bounded stack space.
C. Recursive and nested calls can maintain separate instances of local call state.
D. The function retains correct lexical bindings even after the defining activation would otherwise be gone.
Correct Answer: D. The function retains correct lexical bindings even after the defining activation would otherwise
be gone.
Explanation: The function retains correct lexical bindings even after the defining activation would otherwise be gone. This is
the central value of Closure in the stated situation.
Question 8. Which test most directly verifies correct implementation of Unification?
A. Compile a deliberately ill-typed program and verify it is rejected before execution.
B. Unify a set of compatible constraints and then add one conflicting constraint to verify failure is detected.
C. Infer the type of a small expression with no explicit annotations and verify all uses are consistent.
D. Declare structurally identical named types and verify the type checker still distinguishes them.
Correct Answer: B. Unify a set of compatible constraints and then add one conflicting constraint to verify failure is
detected.
Explanation: Unify a set of compatible constraints and then add one conflicting constraint to verify failure is detected. This
directly validates Unification; the alternatives test different language properties.
, Question 9. A type/runtime design has this flaw: Search only caller links and assume dynamic and lexical
nesting always coincide. Which concept most directly addresses it?
A. Activation record
B. Tail-call optimization
C. Dynamic link
D. Static link
Correct Answer: D. Static link
Explanation: Static link is the direct match. Maintain a static/access link toward the activation record of the relevant lexical
parent.
Question 10. A language implementation must support this behavior: Two record declarations have
identical fields but distinct declared type names, and compatibility should follow declaration identity.
Which semantic/runtime choice best satisfies it?
A. Perform type checking at compile/analysis time using declared or inferred types.
B. Generate type constraints from program structure and solve them to infer missing types.
C. Solve equality constraints between type expressions by finding substitutions for type variables.
D. Treat types as equivalent only when the language says their names or declared identities correspond.
Correct Answer: D. Treat types as equivalent only when the language says their names or declared identities
correspond.
Explanation: Treat types as equivalent only when the language says their names or declared identities correspond.
Programmers can create intentionally distinct abstractions even when underlying representations are identical.
Question 11. A runtime review exposes this problem: Model the expression as a pure mathematical
function and ignore all state changes it performs. Which language-design principle should guide the
repair?
A. Evaluation order
B. Explicit conversion
C. Expression side effects
D. Implicit coercion
Correct Answer: C. Expression side effects
Explanation: Expression side effects is the direct match. Analyze both the produced value and the state change when
reasoning about the expression.
Question 12. When Type inference must make unknown type variables consistent across function
applications and operators., what is the main value of Unification?
A. Many type errors are detected before the program runs and optimizers can rely on stronger invariants.
B. Programs can defer type decisions until runtime, enabling flexible value flow at the cost of later error detection.
C. Concise source code can retain static type guarantees without requiring annotations everywhere.
D. A consistent substitution propagates type information through the program and exposes incompatible constraints.
Correct Answer: D. A consistent substitution propagates type information through the program and exposes
incompatible constraints.
Explanation: A consistent substitution propagates type information through the program and exposes incompatible
constraints. This is the central value of Unification in the stated situation.
ANSWERS AND EXPLANATIONS
Question 1. Which test most directly verifies correct implementation of Evaluation order?
A. Construct side-effecting arguments and verify observed behavior against the documented sequencing rules.
B. Attempt the conversion with and without the explicit syntax and verify only the requested form is accepted.
C. Use a second operand with an observable side effect and verify it is skipped when the first operand determines the
result.
D. Trace the expression followed by a read of the mutated state and verify both value and effect.
Correct Answer: A. Construct side-effecting arguments and verify observed behavior against the documented
sequencing rules.
Explanation: Construct side-effecting arguments and verify observed behavior against the documented sequencing rules. This
directly validates Evaluation order; the alternatives test different language properties.
Question 2. Consider this type/runtime requirement: Programmers should omit many type annotations
while the compiler still determines consistent types. What is the most appropriate language mechanism?
A. Treat types as equivalent only when the language says their names or declared identities correspond.
B. Generate type constraints from program structure and solve them to infer missing types.
C. Associate type information with runtime values and check operations during execution.
D. Perform type checking at compile/analysis time using declared or inferred types.
Correct Answer: B. Generate type constraints from program structure and solve them to infer missing types.
Explanation: Generate type constraints from program structure and solve them to infer missing types. Concise source code
can retain static type guarantees without requiring annotations everywhere.
Question 3. Engineers diagnose the following semantic weakness: Always evaluate both operands before
determining the Boolean result. Which named mechanism is the clearest correction?
A. Evaluation order
B. Implicit coercion
C. Explicit conversion
D. Short-circuit evaluation
Correct Answer: D. Short-circuit evaluation
Explanation: Short-circuit evaluation is the direct match. Use short-circuit semantics for the Boolean operator.
Question 4. When A recursive call occurs in tail position and the implementation wants to avoid
unbounded stack growth., what is the main value of Tail-call optimization?
A. Tail-recursive computations can execute with constant or bounded stack space.
B. Nonlocal lexical bindings can be reached even when the dynamic caller is different.
C. The function retains correct lexical bindings even after the defining activation would otherwise be gone.
D. The runtime can unwind the dynamic call chain correctly on return.
Correct Answer: A. Tail-recursive computations can execute with constant or bounded stack space.
Explanation: Tail-recursive computations can execute with constant or bounded stack space. This is the central value of
Tail-call optimization in the stated situation.
,Question 5. Engineers diagnose the following semantic weakness: Reinterpret the integer bit pattern as a
floating-point value without conversion. Which named mechanism is the clearest correction?
A. Short-circuit evaluation
B. Expression side effects
C. Implicit coercion
D. Explicit conversion
Correct Answer: C. Implicit coercion
Explanation: Implicit coercion is the direct match. Apply the language-defined implicit conversion before performing the
mixed-type operation.
Question 6. Which experiment best validates Static typing rather than a neighboring concept?
A. Unify a set of compatible constraints and then add one conflicting constraint to verify failure is detected.
B. Infer the type of a small expression with no explicit annotations and verify all uses are consistent.
C. Declare structurally identical named types and verify the type checker still distinguishes them.
D. Compile a deliberately ill-typed program and verify it is rejected before execution.
Correct Answer: D. Compile a deliberately ill-typed program and verify it is rejected before execution.
Explanation: Compile a deliberately ill-typed program and verify it is rejected before execution. This directly validates Static
typing; the alternatives test different language properties.
Question 7. A language uses Closure because A function value escapes the scope where it was created
but must still access variables from that lexical environment later. Which benefit most strongly supports
that decision?
A. The runtime can unwind the dynamic call chain correctly on return.
B. Tail-recursive computations can execute with constant or bounded stack space.
C. Recursive and nested calls can maintain separate instances of local call state.
D. The function retains correct lexical bindings even after the defining activation would otherwise be gone.
Correct Answer: D. The function retains correct lexical bindings even after the defining activation would otherwise
be gone.
Explanation: The function retains correct lexical bindings even after the defining activation would otherwise be gone. This is
the central value of Closure in the stated situation.
Question 8. Which test most directly verifies correct implementation of Unification?
A. Compile a deliberately ill-typed program and verify it is rejected before execution.
B. Unify a set of compatible constraints and then add one conflicting constraint to verify failure is detected.
C. Infer the type of a small expression with no explicit annotations and verify all uses are consistent.
D. Declare structurally identical named types and verify the type checker still distinguishes them.
Correct Answer: B. Unify a set of compatible constraints and then add one conflicting constraint to verify failure is
detected.
Explanation: Unify a set of compatible constraints and then add one conflicting constraint to verify failure is detected. This
directly validates Unification; the alternatives test different language properties.
, Question 9. A type/runtime design has this flaw: Search only caller links and assume dynamic and lexical
nesting always coincide. Which concept most directly addresses it?
A. Activation record
B. Tail-call optimization
C. Dynamic link
D. Static link
Correct Answer: D. Static link
Explanation: Static link is the direct match. Maintain a static/access link toward the activation record of the relevant lexical
parent.
Question 10. A language implementation must support this behavior: Two record declarations have
identical fields but distinct declared type names, and compatibility should follow declaration identity.
Which semantic/runtime choice best satisfies it?
A. Perform type checking at compile/analysis time using declared or inferred types.
B. Generate type constraints from program structure and solve them to infer missing types.
C. Solve equality constraints between type expressions by finding substitutions for type variables.
D. Treat types as equivalent only when the language says their names or declared identities correspond.
Correct Answer: D. Treat types as equivalent only when the language says their names or declared identities
correspond.
Explanation: Treat types as equivalent only when the language says their names or declared identities correspond.
Programmers can create intentionally distinct abstractions even when underlying representations are identical.
Question 11. A runtime review exposes this problem: Model the expression as a pure mathematical
function and ignore all state changes it performs. Which language-design principle should guide the
repair?
A. Evaluation order
B. Explicit conversion
C. Expression side effects
D. Implicit coercion
Correct Answer: C. Expression side effects
Explanation: Expression side effects is the direct match. Analyze both the produced value and the state change when
reasoning about the expression.
Question 12. When Type inference must make unknown type variables consistent across function
applications and operators., what is the main value of Unification?
A. Many type errors are detected before the program runs and optimizers can rely on stronger invariants.
B. Programs can defer type decisions until runtime, enabling flexible value flow at the cost of later error detection.
C. Concise source code can retain static type guarantees without requiring annotations everywhere.
D. A consistent substitution propagates type information through the program and exposes incompatible constraints.
Correct Answer: D. A consistent substitution propagates type information through the program and exposes
incompatible constraints.
Explanation: A consistent substitution propagates type information through the program and exposes incompatible
constraints. This is the central value of Unification in the stated situation.