comp.lang.ada
 help / color / mirror / Atom feed
* Ranges and discriminant constraints
@ 2003-06-07 20:58 Vadim Godunko
  2003-06-07 21:51 ` AG
  2003-06-08  2:22 ` David C. Hoos
  0 siblings, 2 replies; 6+ messages in thread
From: Vadim Godunko @ 2003-06-07 20:58 UTC (permalink / raw)


Hello,

Does anybody explain me why language allow constraint discriminant of
discrete type to some value, but not allow constraint to range?

Thanks,
Vadim Godunko



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Ranges and discriminant constraints
  2003-06-07 20:58 Ranges and discriminant constraints Vadim Godunko
@ 2003-06-07 21:51 ` AG
  2003-06-08  6:00   ` Vadim Godunko
  2003-06-08  2:22 ` David C. Hoos
  1 sibling, 1 reply; 6+ messages in thread
From: AG @ 2003-06-07 21:51 UTC (permalink / raw)


"Vadim Godunko" <vgodunko@vipmail.ru> wrote in message
news:665e587a.0306071258.1a8711cc@posting.google.com...

> Does anybody explain me why language allow constraint discriminant of
> discrete type to some value, but not allow constraint to range?

If I understood you correctly you mean something like this: [?]

type abc is (a, b, c);
type test(y: abc) is record
  ...
z: test(a);      -- Which compiles
  vs
z: test(a..c);  -- Which doesn't

Assuming I did understand you correctly,
what would that construct do? The whole
point of a discriminant value is to select
one option out of available set. Ranges
as such are not true values in Ada (you
could do a search for a thread awhile
back which discussed arrays of "nothings"
which existed solely for the purpose of
passing their slices around just to implement
the ranges as variables).





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Ranges and discriminant constraints
  2003-06-07 20:58 Ranges and discriminant constraints Vadim Godunko
  2003-06-07 21:51 ` AG
@ 2003-06-08  2:22 ` David C. Hoos
  2003-06-08  7:21   ` AG
  1 sibling, 1 reply; 6+ messages in thread
From: David C. Hoos @ 2003-06-08  2:22 UTC (permalink / raw)



"Vadim Godunko" <vgodunko@vipmail.ru> wrote in message
news:665e587a.0306071258.1a8711cc@posting.google.com...
> Hello,
>
> Does anybody explain me why language allow constraint discriminant of
> discrete type to some value, but not allow constraint to range?

To constrain a discrete type to a more narrow range, you use a subrtype --
e.g.:

type my_enum is (a, b, c, d, e);

subtype my_constrained_enum is my_enum range b .. d;

>
> Thanks,
> Vadim Godunko
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
>
>





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Ranges and discriminant constraints
  2003-06-07 21:51 ` AG
@ 2003-06-08  6:00   ` Vadim Godunko
  2003-06-08  7:45     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 6+ messages in thread
From: Vadim Godunko @ 2003-06-08  6:00 UTC (permalink / raw)


"AG" <ang@xtra.co.nz> wrote in message news:<b7tEa.15312$JA5.298948@news.xtra.co.nz>...
> "Vadim Godunko" <vgodunko@vipmail.ru> wrote in message
> news:665e587a.0306071258.1a8711cc@posting.google.com...
> 
> > Does anybody explain me why language allow constraint discriminant of
> > discrete type to some value, but not allow constraint to range?
> 
> If I understood you correctly you mean something like this: [?]
> 
> type abc is (a, b, c);
> type test(y: abc) is record
>   ...
> z: test(a);      -- Which compiles
>   vs
> z: test(a..c);  -- Which doesn't
> 
Not exactly. I mean:

type abc is (a, b, c);
type r (k : abc) is record ...

subtype rab is r (a .. b);

procedure p (v : rab);



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Ranges and discriminant constraints
  2003-06-08  2:22 ` David C. Hoos
@ 2003-06-08  7:21   ` AG
  0 siblings, 0 replies; 6+ messages in thread
From: AG @ 2003-06-08  7:21 UTC (permalink / raw)


"David C. Hoos" <david.c.hoos.sr@ada95.com> wrote in message
news:jYwEa.2963$7l6.2875@fe03.atl2.webusenet.com...
>
> "Vadim Godunko" <vgodunko@vipmail.ru> wrote in message
> news:665e587a.0306071258.1a8711cc@posting.google.com...
> > Hello,
> >
> > Does anybody explain me why language allow constraint discriminant of
> > discrete type to some value, but not allow constraint to range?
>
> To constrain a discrete type to a more narrow range, you use a subrtype --
> e.g.:
>
> type my_enum is (a, b, c, d, e);
>
> subtype my_constrained_enum is my_enum range b .. d;

I think it's a little bit trickier that that. What the guy
asked for is something like:

X (my_enum)                -- record
Y  my_enum subtype     -- some constraint here
Z                                   -- subtype of X with discriminant Y

Short of generics, any better ideas?





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Ranges and discriminant constraints
  2003-06-08  6:00   ` Vadim Godunko
@ 2003-06-08  7:45     ` Dmitry A. Kazakov
  0 siblings, 0 replies; 6+ messages in thread
From: Dmitry A. Kazakov @ 2003-06-08  7:45 UTC (permalink / raw)


Vadim Godunko wrote:

> "AG" <ang@xtra.co.nz> wrote in message
> news:<b7tEa.15312$JA5.298948@news.xtra.co.nz>...
>> "Vadim Godunko" <vgodunko@vipmail.ru> wrote in message
>> news:665e587a.0306071258.1a8711cc@posting.google.com...
>> 
>> > Does anybody explain me why language allow constraint discriminant of
>> > discrete type to some value, but not allow constraint to range?
>> 
>> If I understood you correctly you mean something like this: [?]
>> 
>> type abc is (a, b, c);
>> type test(y: abc) is record
>>   ...
>> z: test(a);      -- Which compiles
>>   vs
>> z: test(a..c);  -- Which doesn't
>> 
> Not exactly. I mean:
> 
> type abc is (a, b, c);
> type r (k : abc) is record ...
> 
> subtype rab is r (a .. b);
> 
> procedure p (v : rab);

Maybe because the next requirement could be:

subtype rac is r (a | c);

However, if some time pre-/post-conditions would appear in Ada, one could 
have same effect with:

procedure p (v : r)
   when r.k = a or r.k = c; -- (ad-hoc subtype)

-- 
Regards,
Dmitry A. Kazakov
www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-06-08  7:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-07 20:58 Ranges and discriminant constraints Vadim Godunko
2003-06-07 21:51 ` AG
2003-06-08  6:00   ` Vadim Godunko
2003-06-08  7:45     ` Dmitry A. Kazakov
2003-06-08  2:22 ` David C. Hoos
2003-06-08  7:21   ` AG

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