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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.129.49.78 with SMTP id x75mr1264195ywx.212.1500509195850; Wed, 19 Jul 2017 17:06:35 -0700 (PDT) X-Received: by 10.36.124.88 with SMTP id a85mr49400itd.13.1500509195811; Wed, 19 Jul 2017 17:06:35 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.am4!peer.am4.highwinds-media.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!14no498858qtn.1!news-out.google.com!f71ni2163itc.0!nntp.google.com!t6no295279itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 19 Jul 2017 17:06:35 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=76.113.92.25; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 76.113.92.25 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <9617c73b-e23e-405b-8544-4d17e7e3ad61@googlegroups.com> Subject: Musing on defining attributes and the ability to define an "abstract type X"-interface. From: Shark8 Injection-Date: Thu, 20 Jul 2017 00:06:35 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 3979 X-Received-Body-CRC: 393378466 Xref: news.eternal-september.org comp.lang.ada:47457 Date: 2017-07-19T17:06:35-07:00 List-Id: Also, somewhat tangential to my post on user-defined attributes, if there w= ere a way to define attributes could it perhaps be used to make an "abstrac= t type" interface, allowing something like: Abstract Type Array_Type is record -- Not predefined attributes. Function Index_Count return Positive; Function Index_Type( Index : Positive :=3D 1 ) return (<>); -- As in gene= ric parameters. -- Predefined Array Attributes. Function First ( Index : Positive :=3D 1 ) return Index_Type(Index) with Pre =3D> Index <=3D Array_Type'Index_Count; Function Last ( Index : Positive :=3D 1 ) return Index_Type(Index) with Pre =3D> Index <=3D Array_Type'Index_Count; Function Length ( Index : Positive :=3D 1 ) return Natural is ( Integer'Succ(Array_Type'Last(Index) - Array_Type'First(Index)) ); Function Range ( Index : Positive :=3D 1 ) return Range -- Not in cur= rent Ada. is ( Array_Type'First(Index)..Array_Type'Last(Index) ); -- Predefined Subtype Attributes. Function Alignment return Universal_Integer with Post =3D> Alignment'Result >=3D 0; Function Definite return Boolean; =20 end record; And, of course my example brings up points that would need to be addressed: (1) How would we indicate that Array_Type has a non-null ordered set of ind= exers. [ Array_Type's Range attribute {1..X | x is the dimensionality of th= e array} ] (2) How would we indicate the [sub]types of the indexes are not necessarily= of the same [sub]type? [ex. Array(Integer,character) of X ] (3) How would we indicate the "constrainedness" of a particular index? (Or = does this matter?) [ex Array(Integer range <>,character) of X ] (4) It seems ranges would have to become first-class types in order to sati= sfy the return-value of the Range attribute. (Though perhaps some compiler-= magic like is done w/ Ada.Iterator_Interfaces and the for-loop might handle= that...) (5) It is uncertain whether making these inheritable would be good: on the = plus side you could define an abstract-type that held the READ and WRITE an= d other common attributes and have a hierarchy of "type-classes". (6) The exposure of heretofore conceptual types. (e.g. Universal_Integer) (7) The exposure of the "type of a type". (8) Would it be worth it for compiler-writers? Language maintainers? Langua= ge users? -- On the one hand being able to indicate explicitly that "defini= te type X" has *these* attributes while "Fixed-point type Y" has *those* at= tributes might be pretty nice... especially if we could make interfaces a b= it more consistant. (e.g. allowing both Indefinite_Vector_Var'Length and Ar= ray_Var'Length.) (9) On the user-side I think it would be great to be able to have the Ada.C= ontainers.Vector Vector-type have a compatible interface to Array... we're = halfway there with the Vector_Var'Iterate + For-loop anyway.