next up previous contents index
Next: Explanation of `three apples' Up: Numeric Abstractions Previous: Numeric Abstractions   Contents   Index


Natural Numbers

The basic abstractions in the previous section introduced the selectors true and false as logical constants. Their practical usefulness is very limited if they can be generated only by a more or less complex synthesis of themselves using the basic abstractions.

In practical life truth values are also generated by relational expressions, i.e. by operations comparing numbers or other types of data with one another. This leads us to introduce abstractions defining numbers in A++.

People familiar with computers are very often inclined to look at numbers as mere bit patterns reducing them to a well-structured but dead pile of binary digits.
This is not the natural approach to numbers taken by everyday humans. Another approach to numbers, which was introduced by Alonzo Church in his Lambda Calculus seems quite natural however on the contrary even familiar to little children.

The nunber `3' for example is quite intuitively understood by humans as `3-times'. Thus it is meaningful to say `3 apples', meaning 3 times the entity `apple'.

For a programming language that views numbers as dead bit-patterns it is necessary to express something as simple as `3 apples' using a complicated (relative to what is to be expressed) construct like this:


\begin{lstlisting}[language=C++,stepnumber=2]{}
for (i = 1; i<3; i++) {
<apple>;
}
\end{lstlisting}
Why not just write:

(three apples)
and define `three' as an abstraction looking like this:
\begin{lstlisting}[language=Scm,stepnumber=2]{}
(define three
(lambda (f)
(lambda (x)
(f(f(f x))))))
\end{lstlisting}
Before we can understand this abstraction we have to define apples as well:
\begin{lstlisting}[language=Scm,stepnumber=2]{}
(define apples
(lambda (basket)
(insert-apple basket)
basket))
\end{lstlisting}
The definition of apples shows us that we need something else to make the example work: we need a basket as well, which we assume to be defined as a container somewhere in the environment.

How containers like our basket can be defined we will see shortly in one of the next sections when we talk about collections of data.

The function to put an apple into the basket `insert-apple' we leave also undefined right now, being confidential that it can be defined later without problems.


Subsections
next up previous contents index
Next: Explanation of `three apples' Up: Numeric Abstractions Previous: Numeric Abstractions   Contents   Index
domain access counter Georg P. Loczewski 2004-03-05