Control as data
Introduction / Definition
Control as data represents actions, continuations, states, or decisions as values that can be stored and passed around. Functions and callbacks are common examples. This allows programs to choose behavior dynamically. It is important in event-driven and functional-style designs.
Syntax / Structure / Formula
control value = action/state represented as data
Detailed Explanation
A callback can be stored in a variable and invoked later. A state machine can store a value describing the next state or action.
Example
Example: JavaScript stores callback functions in an event-handler collection.
Output / Result
The program selects and executes behavior dynamically.
Important Points / Notes
- Functions can represent behavior.
- Useful for callbacks and event systems.
Mini Practice Question
Give one example of control represented as data.