From: anon@anon.org (anon)
Subject: Re: Range types
Date: Sun, 21 Oct 2007 21:53:56 GMT
Date: 2007-10-21T21:53:56+00:00 [thread overview]
Message-ID: <UTPSi.252199$ax1.232562@bgtnsc05-news.ops.worldnet.att.net> (raw)
In-Reply-To: 1192994157.867598@athprx04
--
-- 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
next prev parent reply other threads:[~2007-10-21 21:53 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 [this message]
2007-10-21 22:38 ` Christos Chryssochoidis
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox