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: Mats Weber Subject: Re: Syntax for tagged record types and class types Date: 1997/05/22 Message-ID: <338427F3.C08@elca-matrix.ch>#1/1 X-Deja-AN: 243392300 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> To: Matthew Heaney Organization: ELCA Matrix SA Reply-To: Mats.Weber@elca-matrix.ch Newsgroups: comp.lang.ada Date: 1997-05-22T00:00:00+00:00 List-Id: Matthew Heaney wrote: > >package type Stack is > > That's a much more ambitious language change than I am suggesting. A I am not so sure. Package type is just an example of what the syntax could be (see my previous post). I have no problem calling them records. > 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. OK. Make them records. I don't care, because I see package type Stack is procedure Push (X : in Item); function Top return Item; private ... end Stack; as equivalent to type Stack is record procedure Push (X : in Item); function Top return Item; private ... end record; If you don't like the idea of package types, think of them as records in which you can declare subprograms and that can have a private part. BTW, the syntax for task types could be type T is task entry E; end task; which would be more uniform with other type declarations in Ada. > >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: Really ? You need two new keywords, I need zero :-) Seriously, I think constructors and selectors are easily modelled as procedures and functions, so I don't think it's worth adding new concepts here. > 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); More probably The_Stack : Stack'((1, 2, 3, 4, 5)); (one set of parentheses for the qualified expression, and one for the array aggregate). > 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? You do need the tick because otherwise it's the syntax for discriminants instead of constructor parameters (Ada is like that).