Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ncar!ames!hc!lanl!jlg
From: jlg@lanl.gov (Jim Giles)
Newsgroups: comp.lang.fortran
Subject: Data types _without_ pointers
Message-ID: <4026@lanl.gov>
Date: 22 Sep 88 18:10:07 GMT
References: <1032@amelia.nas.nasa.gov>
Organization: Los Alamos National Laboratory
Lines: 84

From article <1032@amelia.nas.nasa.gov>, by fouts@lemming.nas.nasa.gov.nas.nasa.gov (Marty Fouts):
> [...]
> NO. NO. NO. (Gee, I can capshout too ;-)  A pointer is also a
> mechanism by which I introduce an arbitrary data structure into my
> language, allowing me to easily express data structures that the 
> original language designer didn't think to provide.  [...]

I have never seen a data structure that couldn't be described without
pointers.  The first book I read on data structuring was "Structured
Programming" by Dahl, Dijkstra, and Hoare [1972 - I read it for the
first time that very year].  Hoare's chapter on data structuring contains 
a complete listing of the mechanisms needed to define any structure that 
I've ever seen anyone use.  The language should have all of these in 
addition to the basic types of integer and float that it decides to support.

1) Unstructured Data Types:  This was Hoare's name for what Pascal
   calls an enumerated data type.  Example:
             type suit = (club,diamond,heart,spade)

2) The Cartesian Product:  Hoare's name for what Pascal calls records
   and C calls structures.  Example:
             type cardface = (s:suit, r:rank)

3) The Discriminated Union: Hoare's name for Pascal's variant records.
   I believe even C has this concept too :-).  Example:
             type pokercard = (normal:cardface, wild:(joker1, joker2))

4) The Array: Yes, array is a separate data type.  It's not a structure
   built up from lists - it _should_ be a distinct type.  (Multi-d
   arrays should also be allowed and not implemented as array-of-array-....)

5) The Powerset: Hoare's name for Pascal's sets.  Example:
             type hand = powerset of cardface
   A 'hand' may contain from zero up to all 52 cards.

6) The Sequence: Strings, sequential files, etc..  A sequence is a data
   structure made up of an ordered list of data items all of the same
   type.  Sequences have a property of length, which can be explicitly
   kept with the sequence or the sequence may have a distinct member
   which signals the end.  Example:
             type string = sequence of character

7) Recussive Data Structures: Linked lists, etc..  These _are_ defined
   and used in some high-level languages _without_ user visable pointers.
   Example:
             type list = (value:integer, link:list)
   A variable of any recursive data type _may_ have no value at certain
   times during the execution of a code - it should be possible to check
   for this condition.

_NONE_ of these require user accessable pointers not even the linked list!
Items of type 'list' have values of type 'list' - _not_ values of type
'address_of_list'.  In no case may the user of any of these data type
alter the memory location of a data object (without copying the data).
With the addition of an allocate/deallocate mechanism (which is needed
for the recursive data structures anyway - might as well make it
available to all data types), the set is capable of representing _any_
data structure that I've ever seen.  

Now, indeed, the _internal_ representations of these data structures may
ABOUND with pointers.  It is neither the business nor the desire of
most users to concern themselves with the internal implementation of
these things (any more than most users care what type of semiconductor
logic is used in the machine's hardware).

Note: Hoare's chapter goes on to describe how to use the above
structures in combination in order to implement sparse versions
of many of them - also without explicit pointer usage.

So, back to my original statement, pointers are needed _only_ for the
purpose of placing a data type over an arbitrary memory location.  This
is a perfectly useful function.  I might, for example, want to treat
a 27 word SEQUENCE as if it were a 3x3x3 ARRAY.  I _could_ copy it to
an array - but that's time consuming.  I _could_ manipulate the 
sequence directly and do the index calculations explicitly - but that's
hard to read and maintain.  It is more readable - and faster - to
define a pointer to a 3x3x3 array and set it to the address of the
sequence.  This use of pointers for 'structured type coersion' is
perfectly acceptable and is the _only_ reason I can see for including
pointers in a programming language (of course, a suitably constructed
run-time EQUIVALENCE would serve the same function).

J. Giles
Los Alamos