From: eachus@Dr_No.mitre.org (Robert I. Eachus)
Subject: Re: New Tree Example (was Re: MI - clutchin
Organization: The Mitre Corp., Bedford, MA.
	<1992Oct2.155045.18473@Urmel.Informatik.RWTH-Aachen.DE>
Date: Sat, 3 Oct 1992 02:35:57 GMT


   Okay, once more into the fray, but based on some of Peter's
comments this is getting to the point of diminishing returns for now.
(Not a criticism of Peter, but we are at the edge of the current state
of definition of Ada 9X.  Before I say more about how you should
program in Ada 9X, the language needs to be closer to frozen.)

In article <1992Oct2.155045.18473@Urmel.Informatik.RWTH-Aachen.DE>
pk@rwthi3.informatik.rwth-aachen.de (Peter Klein) writes:

   In article 92Sep18160904@Dr_No.mitre.org, eachus@Dr_No.mitre.org
(Robert I. Eachus) writes:

   >> -- You can do all this with just a little attention to magic in
   >> -- Ada 83.  (Each instance of New_Elements gets a unique tag
   >> -- from Mixed_Lists, and does run-time type checking when
   >				 ^^^^^^^^^^^^^^^^^^^^^^
   > -- removing things from lists by matching tags.  Of course, in
   > -- Ada 9X you can use tagged types to do that automatically.)

   > Well, this is exactly what's wrong with your example. You loose
the
   > ability to treat all elements in the list in a uniform way: Using
   > generics, it is the *client* of the list package who determines
how
   > to do certain things with the elements...

   > One important point here: We are talking about *single
   > inheritance* so far.

   I don't understand what you are criticizing.  Of course it is
single inheritance, and of course it is unnecessarily difficuly in Ada
83.  But what I was pointing out was that, while single inheritance is
natural in Ada 9X, it is not impossible in Ada 83.  (Just painful in
some cases.)

   >> Having said all that, this is the wrong way round, especially in
   >> Ada 9X.  First create the node type, which may just be a
placeholder,
   >> then mix in the lists, then derive the various element types
from the
   >> node type:
   >>
   >> type Node_Type is tagged record null; end record;
   >>
   >> generic
   >> type Element is tagged private;
   >> package Lists is
   >> type Item is new Element with null; -- (I don't like the syntax
either.)
   >> type List is private;
   >> -- define list operations here. (But make sure they are class
wide.)
   >> private
   >> ...
   >> end Lists;
   >>
   >> package Node_Lists is new Lists(Node_Type);
   >>
   >> package Identifiers is
   >> type Identifier_Node is new Node_Lists.Item with private;
   >> -- operations on identifiers go here.
   >> private
   >> ...
   >> end Identifiers;
   >>
   >> -- etc., etc.
   >>

   > Excuse me here; my knowledge of Ada 9X syntax doesn't suffice to
   > understand this example.

    It corresponds to creating a list class in say, Smalltalk, and
deriving from it.  However there is a very subtle but important
difference, you actually don't inherit from the list class, but from
the "element of list" class.  The list type is not an extensible type,
but it is possible to make lists of all types derived from
Node_Lists.Item. In effect the adding of the list operations involves
inheritance from the element type with a mixin of list attributes.
However, there is a single list type.  Deriving from Node_Lists.Item
creates a new class, but all the list operations still operate on the
single list type.  (You could derive from Node_Type and instantiate
Lists again if you wanted the two types to have different list types.)
So this is a form of multiple inheritance, but a fairly safe one.

  > :) Don't think so. Actually, if I follow your advice to keep the
  > attribute of 'listable element' apart from other attributes of the
  > element, this is exactly the place where multiple inheritance
  > comes back into the game again.  In this case, I make up a virtual
  > base class listable_element, which defines the 'shape' of an
  > element which can be put into the list. Since this feature of
  > being listable has got nothing to do with other properties of an
  > element, it has to be assumed that some possible list element type
  > also is in some arbitrary class hierarchy. Now, if I want to put
  > elements of an arbitrary type (possibly a subtype of an arbitrary
  > supertype) into my list, I'll make this type a subtype of
  > listable_element also. Which, in general, implies that it inherits
  > from at least two supertypes.

    I had to play with this awhile until I understood the percieved
problem.  The misunderstanding is that in Ada you can sort of derive
through a class to add operations, so if you want to add many
attributes you can have many ancestors instead of many parents.  Let's
say that above you are talking about two parent classes LISTABLE and
ARBITRARY, and a (single) child of both (Single for artistic
simplicity, I'm not going to try to draw the multiple child case):

               LISTABLE	    ARBITRARY
		      \       /
		       \     /
                        \   /
                        CHILD

    In Ada you get something more like:

                      ARBITRARY			 LISTS
                          |			   |
			  |
                          |			   |
                          |
                          |			   |
                      LISTABLE_CHILD- - - - -LISTS_OF_CHILDREN

    The instantiation which creates both LISTABLE_CHILD and
LISTS_OF_CHILDREN looks like a mixin, but notice that it actually
creates two types, and operations (such as APPEND) which are
operations of both types.  (I dotted the relationship between LISTS
and LISTS_OF_CHILDREN because it is really a template-instance
relationship rather than parent child.  LISTABLE_CHILD however is a
true child of ARBITRARY.)


--

					Robert I. Eachus

with STANDARD_DISCLAIMER;
use  STANDARD_DISCLAIMER;
function MESSAGE (TEXT: in CLEVER_IDEAS) return BETTER_IDEAS is...