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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,da3af210412d89fd X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!news3.google.com!news.germany.com!feeder.erje.net!tudelft.nl!txtfeed1.tudelft.nl!newsfeed.CARNet.hr!news.grnet.gr!newsfd02.forthnet.gr!not-for-mail From: Christos Chryssochoidis Newsgroups: comp.lang.ada Subject: Re: Range types Date: Mon, 22 Oct 2007 01:38:11 +0300 Organization: FORTHnet S.A., Atthidon 4, GR-17671 Kalithea, Greece, Tel: +30 2109559000, Fax: +30 2109559333, url: http://www.forthnet.gr Message-ID: <471BD4D3.4000009@gmail.com> References: <1192994157.867598@athprx04> NNTP-Posting-Host: athprx04.forthnet.gr Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1253; format=flowed Content-Transfer-Encoding: 7bit X-Trace: athprx02.forthnet.gr 1193006298 20415 193.92.150.70 (21 Oct 2007 22:38:18 GMT) X-Complaints-To: abuse@forthnet.gr NNTP-Posting-Date: Sun, 21 Oct 2007 22:38:18 +0000 (UTC) To: anon User-Agent: Thunderbird 2.0.0.6 (Macintosh/20070728) In-Reply-To: Cache-Post-Path: newsfd02!unknown@acro.ath.forthnet.gr Xref: g2news2.google.com comp.lang.ada:2533 Date: 2007-10-22T01:38:11+03:00 List-Id: 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 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 >