On 18-03-06 22:45 ,
gautier...@hotmail.com wrote:
>> for definition: please have a look at
>>
https://en.wikipedia.org/wiki/Recursive_data_type
>
> "In computer programming languages, a recursive data type (also known
> as a recursively-defined, inductively-defined or inductive data type)
> is a data type for values that may contain other values of the same
> type."
>
> The definition given above is nonsensical: either the data type is
> empty or infinitely large...
No, the definition makes mathematical sense. Even if the "contained"
values are of the same _type_ as the containing value, they are
different (and "smaller") _values_, so the recursive containment can
terminate.
For example, in mathematics the set of natural numbers, N, is usually
defined in this recursive way:
"zero", 0, is the empty set: {}
"one", 1, is the set that contains zero: {0}
"two", 2, is the set that contains zero and one: {0,1}
and so on.
Inductively, a number n is the set that contains the numbers smaller
than n: {0, 1, ..., n-1}.
> In the examples given (List), the type names can mean either a
> pointer to the real data, or the data itself (a list's node in that
> case). Clearly they are playing with words there: a node doesn't
> really contain the next node, but a pointer (or a reference) to the
> next node. So it's not really recursive, only in appearance. They
> play with a shortcut notation.
They are defining a mathematical (view of a) "type", which can be
implemented in various ways in a programming language. Of course I agree
that implementations normally use pointers, mainly to avoid copying
large values (and to allow values with cycles). In the example, I think
List is simply a "by reference" type, so all "List" variables are pointers.
One can certainly implement this "List" type in Ada, without pointers,
by implementing a List-of-A as the Ada type array (Positive range <>) of
A, where the head element of a list L is L(L'First) and the tail is
L(L'First+1 .. L'Last). Each "cons" operation would of course require
making a copy of the operand list, but that is just implementation detail.
--
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
. @ .