From: Christos Chryssochoidis <C.Chryssochoidis@gmail.com>
To: anon <anon@anon.org>
Subject: Re: Range types
Date: Mon, 22 Oct 2007 01:38:11 +0300
Date: 2007-10-22T01:38:11+03:00 [thread overview]
Message-ID: <471BD4D3.4000009@gmail.com> (raw)
In-Reply-To: <UTPSi.252199$ax1.232562@bgtnsc05-news.ops.worldnet.att.net>
Thanks! This is indeed a very good solution to the problem I posed. And
that's what I'll probably end up doing. I thought too about defining a
function (predicate) that would decide whether a given value falls in
the legal ranges. But by doing the discrimination with a function, I
wouldn't have a "concrete" type to work with...
Thanks very much,
C.C.
anon wrote:
> --
> -- From the syntax rules of RM 3.2.1, 3.2.2 and 3.5 the
> -- simple answer is no for integer scalar types.
> --
> -- One way to do this is to exclude the values you want
> -- in the logical of the program
> --
> with Ada.Text_IO ;
> use Ada.Text_IO ;
>
> procedure t is
>
> --
> -- creates a master constraint type
> --
> type My_Int_Base is range 1..200 ;
>
> --
> -- creates an excluded type
> --
> subtype My_Int_Exclude_Subtype is My_Int_Base range 101..149 ;
>
>
> Var_0 : My_Int_Base ;
>
> begin
>
> -- set Var_0 valid
>
> Put_Line ( "Var_0 => 75" ) ;
> Var_0 := 75 ;
>
> --
> -- Verify that value of Var_0 is not excluded
> --
> if Var_0 in My_Int_Exclude_Subtype then
> raise Constraint_Error ;
> end if ;
>
> --
> -- Use Var_0
> --
> Put_Line ( " Var_0 => Valid" ) ;
>
> --
> -- Set Var_0 invalid
> --
> Put_Line ( "Var_0 => 125" ) ;
> Var_0 := 125 ;
>
> --
> -- Verify that value of Var_0 is not excluded
> --
> if Var_0 in My_Int_Exclude_Subtype then
> raise Constraint_Error ;
> end if ;
>
> --
> -- Use Var_0
> --
> Put_Line ( " Var_0 => Valid" ) ;
>
> exception
> when Constraint_Error =>
> Put_Line ( " Var_0 => Constraint_Error" ) ;
> end t ;
>
>
>
> In <1192994157.867598@athprx04>, Christos Chryssochoidis <C.Chryssochoidis@gmail.com> writes:
>> Hi,
>>
>> I have a question regarding the range types in Ada. Is there any way to
>> specify that a type is, say, the values 1..100 and additionally the
>> values 150..200? I tried something like
>>
>>> type My_Int is range 1..100, 150..200;
>>
>>
>> and
>>
>>> type My_Int is range 1..100 | 150..200;
>>
>> but without success. I also tried doing this within an enumeration, but
>> failed again. Is it possible to define such type, consisting of multiple
>> ranges?
>>
>>
>> Thanks very much for any answer.
>>
>>
>> Christos Chryssochoidis
>
prev parent reply other threads:[~2007-10-21 22:38 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-21 19:15 Range types Christos Chryssochoidis
2007-10-21 20:23 ` Niklas Holsti
2007-10-21 21:28 ` Christos Chryssochoidis
2007-10-22 0:06 ` Robert A Duff
2007-10-22 7:23 ` Jacob Sparre Andersen
2007-10-22 11:14 ` Christos Chryssochoidis
2007-10-22 12:33 ` Georg Bauhaus
2007-10-22 19:08 ` Christos Chryssochoidis
2007-10-23 23:52 ` anon
2007-10-24 12:57 ` Christos Chryssochoidis
2007-10-21 21:53 ` anon
2007-10-21 22:38 ` Christos Chryssochoidis [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox