next up previous contents index
Next: Remark: Up: Basic Abstractions Previous: Basic Abstractions   Contents   Index


The IF- Abstraction

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.
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:

  1. a condition having a certain truth value (true or false),
  2. the first block of code and
  3. the second block of code.
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 selector.

Having thus analyzed the essence of an IF-function we may code it as a `lambda abstraction':



\begin{lstlisting}[language=Scm,stepnumber=2]{}
(define if (lambda (sel a b)
(sel a b)))
\end{lstlisting}


Subsections

domain access counter Georg P. Loczewski 2004-03-05