Up: Basic Abstractions
Previous: Basic Abstractions
One of the most basic operation in any programming language
is to make a decision, to select a block of code
depending on the truth value of a certain argument.
The IF- Abstraction
Such an operation people have in mind, when they talk about IF-statements, IF-THEN-ELSE-constructs, alternative structures and a few more.
We can very well say that the IF-statement has the function to select code to be evaluated or executed. The IF-statement therefore is a function taking three arguments:
Because the selection of the code block to be evaluated or executed depends on the first argument, we can look at the first argument as a
- a condition having a certain truth value (true or false),
- the first block of code and
- the second block of code.
Having thus analyzed the essence of an IF-function we may code it
as a `lambda abstraction':
(define if (lambda (sel a b)
(sel a b)))
Georg P. Loczewski