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.2 required=5.0 tests=BAYES_00,FREEMAIL_FROM, FROM_STARTS_WITH_NUMS autolearn=no autolearn_force=no version=3.4.4 X-Received: by 10.36.236.3 with SMTP id g3mr11533716ith.32.1519731833894; Tue, 27 Feb 2018 03:43:53 -0800 (PST) X-Received: by 10.157.22.195 with SMTP id s3mr632406ots.13.1519731833681; Tue, 27 Feb 2018 03:43:53 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.am4!peer.am4.highwinds-media.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!w142no192947ita.0!news-out.google.com!a25ni382itj.0!nntp.google.com!w142no192946ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 27 Feb 2018 03:43:53 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=85.240.208.48; posting-account=rhqvKAoAAABpikMmPHJSZh4400BboHwT NNTP-Posting-Host: 85.240.208.48 References: <62f83fe5-15d6-41cf-952f-bc3cb077d42f@googlegroups.com> <473f9b1a-6466-4745-9041-107f54062cf2@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <576b1f3a-a0f4-42c9-b7b5-082600ad74c5@googlegroups.com> Subject: Re: [Newbie] doubly constrained array, dumb question From: Mehdi Saada <00120260a@gmail.com> Injection-Date: Tue, 27 Feb 2018 11:43:53 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Received-Body-CRC: 401726509 X-Received-Bytes: 4047 Xref: reader02.eternal-september.org comp.lang.ada:50679 Date: 2018-02-27T03:43:53-08:00 List-Id: > For example, the "class" Integer of which=20 > Positive is a "member" still has negative values, it is just so that you= =20 > cannot tag them Positive. E.g. > A : Positive :=3D 1; > B : Positive :=3D 100; > C : Positive :=3D (A - B) + B; -- This is OK, though A - B =3D -99 Interesting, I never tried that ! Very useful indeed. But those types don't have classes, nor polymorphism. The compiler can't de= cide at runtime the type of, said, an integer or a real, and determine the = constraints allowed and subprograms defined for, with a virtual table. No d= ynamic binding for untagged types. But I guess you would probably want that= ! > Not necessarily. You simply override disallowed operations with bodies=20 > raising Constraint_Error. The same technique is used for multiple dispatc= h: Yes, I thought so, but it's definitely not my conception of safe and "predi= ctable"... It's safer that "whatever is defined for the parent, won't raise= exception for the descendants" holds true at any time. > > Could you give an example of 10, the syntax you would like ? > type Kind_Of is (Wake_Up, Notify, Warning, Error, Alarm); > task type Monitor is > entry Signal (Kind_Of) (No : Positive; Name : String); > end Monitor; > Now if you wanted to constrain Signal to only Wake_Up..Notify, that=20 > would not go. I see. I can't really imagine a new syntax that would fit with the pre-exis= ting one to do just that since (a far as I get it) true that constraining r= ecord/tagged types works by constraining type declarations, not type defini= tions (components and methods). > Sometimes it is quite annoying, e.g. when declaring large nested record= =20 > types: > type Foo is record > A : record ... end record; -- Illegal > B : array (...) of ...; -- Illegal > end record; I do like anonymous-anything, but isn't a bit overkill here ? If instanciation takes you as much time or space than definition, I underst= ood you would like to spare you that, but for a record object, instanciatio= n takes one line, definition much more. You would lose in readibily with an= onymous record objects for no gain. > Sometimes one wants anonymous types of arguments: > procedure Init > ( Section_1 : record ... end record; Same here. Declare record types or arrays to do the trick. Plus a type spec= ification like that would most unreadable.=20 > No, it can be allocated on the stack and be a component of another type.= =20 > It is a very important mechanism as it allows to avoid implicit use of=20 > the heap. Ah, I knew there was something more behind. Ok !