comp.lang.ada
 help / color / mirror / Atom feed
From: Mehdi Saada <00120260a@gmail.com>
Subject: Re: [Newbie] doubly constrained array, dumb question
Date: Tue, 27 Feb 2018 03:43:53 -0800 (PST)
Date: 2018-02-27T03:43:53-08:00	[thread overview]
Message-ID: <576b1f3a-a0f4-42c9-b7b5-082600ad74c5@googlegroups.com> (raw)
In-Reply-To: <p737oh$102b$1@gioia.aioe.org>

> For example, the "class" Integer of which 
> Positive is a "member" still has negative values, it is just so that you 
> cannot tag them Positive. E.g.
>     A : Positive := 1;
>     B : Positive := 100;
>     C : Positive := (A - B) + B; -- This is OK, though A - B = -99
Interesting, I never tried that ! Very useful indeed.
But those types don't have classes, nor polymorphism. The compiler can't decide 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 dynamic binding for untagged types. But I guess you would probably want that !

> Not necessarily. You simply override disallowed operations with bodies 
> raising Constraint_Error. The same technique is used for multiple dispatch:
Yes, I thought so, but it's definitely not my conception of safe and "predictable"... 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 
> would not go.
I see. I can't really imagine a new syntax that would fit with the pre-existing one to do just that since (a far as I get it) true that constraining record/tagged types works by constraining type declarations, not type definitions (components and methods).

> Sometimes it is quite annoying, e.g. when declaring large nested record 
> 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 understood you would like to spare you that, but for a record object, instanciation takes one line, definition much more. You would lose in readibily with anonymous 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 specification like that would most unreadable. 

> No, it can be allocated on the stack and be a component of another type. 
> It is a very important mechanism as it allows to avoid implicit use of 
> the heap.
Ah, I knew there was something more behind. Ok !


  reply	other threads:[~2018-02-27 11:43 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-26 16:26 [Newbie] doubly constrained array, dumb question Mehdi Saada
2018-02-26 17:02 ` J-P. Rosen
2018-02-26 21:40   ` Dmitry A. Kazakov
2018-02-26 23:26   ` Randy Brukardt
2018-02-27  9:01     ` Simon Wright
2018-02-27 22:11       ` Randy Brukardt
2018-02-26 20:52 ` Niklas Holsti
2018-02-27  1:29 ` Mehdi Saada
2018-02-27  9:18   ` Dmitry A. Kazakov
2018-02-27 11:43     ` Mehdi Saada [this message]
2018-02-27 14:19       ` Dmitry A. Kazakov
2018-02-27 17:08     ` G. B.
2018-02-27 17:37       ` Dmitry A. Kazakov
2018-02-27 14:34   ` Jere
2018-02-27 15:13     ` Dmitry A. Kazakov
2018-02-27  7:38 ` Jacob Sparre Andersen
replies disabled

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