Chapter 3 Revision: Control and Program Structure
Control structures govern how instructions are scheduled, evaluated, suspended, and routed. From structured looping invariants and hardware activation records to cooperative coroutines and first-class continuations, program structure defines how software coordinates complex state across time.
Use these flashcards for active recall. Try to answer the question out loud before clicking the card to flip it.
Flashcards 🎴
What does treating 'Control as Data' mean in programming language design?
What are Loop Invariants and Loop Variants in formal verification?
• Loop Variant (v): An integer measure that strictly decreases each iteration toward a bound, proving termination (total correctness).
How do Coroutines and Subroutines differ in stack allocation and lifetime?
• Coroutines: Asymmetric/symmetric cooperative concurrency;
yield suspends execution and retains local variables and instruction pointers in heap-allocated frames for future resume.What is Referential Transparency in Pure Functions?
f(x) can be substituted with its evaluated value anywhere in the program without altering observable behavior, free of side effects (no hidden state mutation, I/O, or non-determinism).What are the trade-offs between Exceptions and Monadic Result types?
• Result/Option Types: Explicit algebraic return types; enforce compile-time error handling with zero stack-unwinding overhead.
What does a Call Stack Activation Record (Stack Frame) contain?