comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@ni.net (Matthew Heaney)
Subject: Re: Syntax for tagged record types and class types
Date: 1997/05/21
Date: 1997-05-21T00:00:00+00:00	[thread overview]
Message-ID: <mheaney-ya023680002105972330150001@news.ni.net> (raw)
In-Reply-To: 33830D58.6D8F@elca-matrix.ch


In article <33830D58.6D8F@elca-matrix.ch>, Mats.Weber@elca-matrix.ch wrote:

>So do I. And if tasks and protected types provide that kind of notation,
>why should this not also be true for other constructs ?

Agreed.  Selection should be consistent for all objects.  The "principle of
uniform reference," and all that.

>That's why I proposed to use package types in my thesis (at
><http://lglwww.epfl.ch/Team/MW/Ada-Extensions/Ada-Extensions.html>).
>You example would be written
>
>package type Stack is

That's a much more ambitious language change than I am suggesting.  A
package is a module, not a type, and it's simply the mechanism by which one
controls namespace.  Modules and types are orthogonal language constructs
in Ada, and like it or not, we should keep it that way.

>All three approaches are essentially equivalent. I chose package types
>because packages already have a private part, which is very useful, and
>because I make some further use of the task-package similarity that is
>very useful for expressing abstract data types that are needed in both
>concurrent and non-concurrent variants (e.g. Booch components).

Adding selectors and constructors to the language is far simpler, and a
much better fit to what is already there.  The syntax for both can look
like functions:

type Stack is private;

selector Top (S : Stack) return Item;
or
selector Stack.Top return Item;

constructor Stack (Items : Item_Array);
or
constructor Initialize (Items : Item_Array) return Stack;

So that I can do this:

The_Stack : Stack'(1, 2, 3, 4, 5);
or
The_Stack : Stack'Initialize (1, 2, 3, 4, 5);

I got the idea for a "named" constructor from Ian Joyner in has C++
Critique paper.  We already have a precedent in the language for
T'<function> in attributes, so we could borrow that for constructors.

The tick comes from attribute syntax, plus from the fact that that is how
you initialize a heap variable.

It also gives us a way of avoiding the use of the assignment "operator,"
thus allowing a constructor "function" to initialize a limited object. 
That means limited objects don't have to be definate.  Example, I could
have a factory method to return an iterator that is limited and class-wide:

procedure Copy (From : Root_Stack'Class; To : in out Root_Stack) is

   The_Iterator : Root_Stack_Iterator'Class'New_Iterator (From'Access);
begin

In Ada 95, I can only do the above example by putting the active iterator
on the heap. 


>My proposal for constructors goes like this:
>
>package type T is
>   procedure new (X : Integer; Y : Float);   -- Note: new is a keyword
>   ...
>end T;
>
>...
>
>Object : T(X => 5, Y => 3.14);

And my ideas were

package P is

   type T is tagged private;

   constructor T (X : Integer; Y : Float);
or 
   constructor Initialize (X : Integer; Y : Float) return T;

So that I could

O : T (X => 5, Y => 3.14);
O : T'(5, 3.14);  -- do we need the tick?
or
O : T'Initialize (X => 5, Y => 3.14);

Perhaps the need for a named constructor isn't obvious in this example. 
Consider this one:

type File_Type is limited private;

constructor Open (Name : String; Mode : File_Mode) return File_Type;

declare
   The_File : File_Type'Open (Name => "mats_weber.dat", Mode => In_Mode);
begin

The_File is a modifiable object, just like it would be without the constructor.

Perhaps we do need the tick; we wouldn't want to confuse discriminants with
constructor arguments.  At least the tick notation calls out the
difference.

Gee, isn't armchair language design fun?

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




  reply	other threads:[~1997-05-21  0:00 UTC|newest]

Thread overview: 120+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-04-23  0:00 Not intended for use in medical, Robert C. Leif, Ph.D.
1997-04-24  0:00 ` J. Florio
1997-04-25  0:00 ` Kevin Cline
1997-04-25  0:00   ` Robert Dewar
1997-04-25  0:00 ` Ken Garlington
1997-04-28  0:00 ` John Apa
1997-04-28  0:00   ` John M. Mills
1997-04-30  0:00     ` Larry Kilgallen
1997-05-02  0:00       ` Nick Roberts
1997-04-28  0:00   ` Robert Dewar
1997-04-29  0:00     ` Kaz Kylheku
1997-04-30  0:00       ` John Apa
     [not found]       ` <3367CE1E.5ED1@die_spammer.dasd.honeywell.com>
1997-05-01  0:00         ` Kaz Kylheku
1997-05-03  0:00       ` Simon Wright
1997-05-04  0:00         ` Kaz Kylheku
1997-05-04  0:00           ` Robert Dewar
1997-05-04  0:00             ` Richard Kenner
1997-05-05  0:00             ` Kaz Kylheku
1997-05-06  0:00               ` Kaz Kylheku
1997-05-06  0:00                 ` Robert A Duff
1997-05-07  0:00                   ` Kaz Kylheku
1997-05-08  0:00                     ` Robert A Duff
1997-05-07  0:00                   ` Robert Dewar
1997-05-08  0:00                     ` John G. Volan
1997-05-10  0:00                       ` Robert Dewar
1997-05-10  0:00                         ` John G. Volan
1997-05-11  0:00                           ` Robert Dewar
1997-05-11  0:00                             ` John G. Volan
1997-05-11  0:00                               ` Robert A Duff
1997-05-12  0:00                                 ` John G. Volan
1997-05-12  0:00                                 ` Robert Dewar
1997-05-11  0:00                             ` John G. Volan
1997-05-11  0:00                               ` Robert Dewar
1997-05-12  0:00                             ` John G. Volan
1997-05-12  0:00                               ` Robert Dewar
1997-05-17  0:00                               ` Robert I. Eachus
     [not found]                                 ` <dewar.863877808@merv>
1997-05-17  0:00                                   ` Robert Dewar
1997-05-17  0:00                                     ` Jon S Anthony
1997-05-21  0:00                                       ` Syntax for tagged record types (was Re: Not intended for use in medical,) Ben Brosgol
1997-05-20  0:00                                         ` Matthew Heaney
1997-05-21  0:00                                           ` Jon S Anthony
1997-05-21  0:00                                             ` Matthew Heaney
1997-05-22  0:00                                               ` Robert I. Eachus
1997-05-25  0:00                                                 ` Matthew Heaney
1997-05-28  0:00                                                   ` Robert I. Eachus
1997-05-23  0:00                                               ` Jon S Anthony
1997-05-23  0:00                                                 ` Simon Wright
1997-05-23  0:00                                                 ` Matthew Heaney
1997-05-25  0:00                                                   ` Jon S Anthony
1997-05-28  0:00                                                   ` Syntax for tagged record types (was Re David Kristola
1997-05-21  0:00                                           ` Syntax for tagged record types and class types Mats Weber
1997-05-21  0:00                                             ` Matthew Heaney [this message]
1997-05-22  0:00                                               ` Mats Weber
1997-05-27  0:00                                               ` Tucker Taft
1997-05-30  0:00                                                 ` Mats.Weber
1997-05-22  0:00                                             ` Samuel A. Mize
1997-05-22  0:00                                               ` Samuel A. Mize
1997-05-23  0:00                                               ` Mats Weber
     [not found]                                         ` <mheaney-ya023680002005972314260001@news.ni.net <mheaney-ya023680002105972302430001@news.ni.net>
1997-05-22  0:00                                           ` Syntax for tagged record types (was Re: Not intended for use in medical,) Robert A Duff
1997-05-22  0:00                                             ` John G. Volan
1997-05-23  0:00                                               ` Matthew Heaney
1997-05-23  0:00                                                 ` Jon S Anthony
1997-05-23  0:00                                                   ` Matthew Heaney
1997-05-25  0:00                                                     ` Robert Dewar
1997-05-25  0:00                                                     ` Jon S Anthony
1997-05-27  0:00                                                     ` Ray Blaak
1997-05-23  0:00                                                   ` John G. Volan
1997-05-24  0:00                                                     ` Robert A Duff
1997-05-24  0:00                                                       ` Matthew Heaney
1997-05-28  0:00                                                         ` Robert I. Eachus
1997-05-25  0:00                                                     ` Jon S Anthony
1997-05-23  0:00                                               ` Jon S Anthony
1997-05-12  0:00                             ` Not intended for use in medical, John G. Volan
1997-05-12  0:00                         ` Language Design Mistakes (was "not intended...") W. Wesley Groleau (Wes)
1997-05-13  0:00                           ` Robert Dewar
1997-05-13  0:00                             ` Robert A Duff
1997-05-14  0:00                               ` Robert Dewar
1997-05-13  0:00                             ` W. Wesley Groleau (Wes)
1997-05-08  0:00                     ` Not intended for use in medical, Kaz Kylheku
1997-05-08  0:00                       ` Robert Dewar
1997-05-09  0:00                         ` Kaz Kylheku
1997-05-12  0:00                       ` W. Wesley Groleau (Wes)
1997-05-12  0:00                         ` John G. Volan
1997-05-14  0:00                       ` Nick Roberts
1997-05-14  0:00                         ` Robert Dewar
1997-05-14  0:00                           ` Jeff Carter
     [not found]                             ` <dewar.863632434@merv>
1997-05-15  0:00                               ` Kaz Kylheku
1997-05-18  0:00                                 ` Robert Dewar
1997-05-15  0:00                         ` Kaz Kylheku
1997-05-08  0:00                     ` Robert A Duff
1997-05-09  0:00                       ` Robert I. Eachus
1997-05-11  0:00                         ` Robert Dewar
1997-05-11  0:00                           ` Matthew Heaney
1997-05-12  0:00                             ` Robert Dewar
1997-05-12  0:00                               ` Matthew Heaney
1997-05-13  0:00                                 ` Jon S Anthony
1997-05-13  0:00                                   ` Matthew Heaney
1997-05-14  0:00                                     ` Robert Dewar
1997-05-14  0:00                                     ` Robert Dewar
1997-05-14  0:00                                 ` Nick Roberts
1997-05-14  0:00                                 ` Robert Dewar
1997-05-14  0:00                                 ` Robert Dewar
1997-05-15  0:00                                   ` W. Wesley Groleau (Wes)
1997-05-12  0:00                           ` Robert I. Eachus
1997-05-13  0:00                             ` Robert Dewar
1997-05-14  0:00                               ` Nick Roberts
1997-05-14  0:00                                 ` Robert Dewar
     [not found]                                   ` <01bc6182$30e3a7c0$LocalHost@xhv46.dial.pipex.com>
1997-05-16  0:00                                     ` Robert Dewar
1997-05-16  0:00                                     ` Robert A Duff
1997-05-16  0:00                                       ` Robert I. Eachus
1997-05-18  0:00                                         ` Nick Roberts
1997-05-18  0:00                                           ` Matthew Heaney
1997-05-19  0:00                                             ` Robert A Duff
1997-05-19  0:00                                             ` Robert I. Eachus
1997-05-19  0:00                                               ` Matthew Heaney
1997-05-20  0:00                                                 ` Nick Roberts
1997-05-20  0:00                                                   ` Matthew Heaney
1997-05-21  0:00                                                     ` Dale Stanbrough
1997-05-04  0:00         ` Robert Dewar
1997-05-04  0:00         ` Richard Kenner
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox