Normal-order reduction
Introduction / Definition
Normal-order reduction is an important concept in programming-language design and software development. It provides a way to organize, describe, or reason about computation and data. Understanding this concept helps a learner connect the syntax of a program with its underlying behavior. It is also useful when comparing different programming styles and choosing appropriate abstractions. The goal is to understand both what normal-order reduction means and why it is useful in real programs.
Syntax
reduce outermost-leftmost expression first
Detailed Explanation
Normal-order reduction selects an outermost, typically leftmost, reducible expression before reducing inner expressions. This can delay evaluation of arguments until they are actually needed. It can therefore avoid some unnecessary computations. However, repeated use of a delayed argument can duplicate work unless results are shared.
Example
(lambda x: 1)(expensive())
Output
1
Important Points / Notes
- Understand the purpose of normal-order reduction.
- Separate the concept from its particular syntax.
- Trace the example step by step.
- Consider both benefits and limitations.
- Use the concept only when it improves program clarity or correctness.
Mini Practice Question
Why can normal-order reduction avoid evaluating an unused argument?