From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.7 required=5.0 tests=BAYES_00,INVALID_MSGID, PDS_OTHER_BAD_TLD autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d1df6bc3799debed X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: Syntax for tagged record types and class types Date: 1997/05/21 Message-ID: #1/1 X-Deja-AN: 243097189 References: <3.0.32.19970423164855.00746db8@mail.4dcomm.com> <5kl9qc$g4d@bcrkh13.bnr.ca> <5kmek2$9re@bcrkh13.bnr.ca> <33727FA5.5C7A@sprintmail.com> <3374C19F.15FE@sprintmail.com> <3376CF85.3E15@sprintmail.com> <33828299.2A3@world.std.com> <33830D58.6D8F@elca-matrix.ch> Organization: Estormza Software Newsgroups: comp.lang.ada Date: 1997-05-21T00:00:00+00:00 List-Id: 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 >). >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' 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 (818) 985-1271