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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,36208f5925ed5269 X-Google-Attributes: gid103376,public From: Robert Dewar Subject: Re: non-consecutive ranges Date: 1999/05/01 Message-ID: <7gesqf$pfc$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 472917296 References: <7gct90$7hr$1@nnrp1.dejanews.com> X-Http-Proxy: 1.0 x11.dejanews.com:80 (Squid/1.1.22) for client 205.232.38.14 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Sat May 01 12:41:51 1999 GMT Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.04 [en] (OS/2; I) Date: 1999-05-01T00:00:00+00:00 List-Id: In article <7gct90$7hr$1@nnrp1.dejanews.com>, vlight@my-dejanews.com wrote: > > > is there a way to define a variable to have a non-consecutive range? > for instance, let's say i wanted to define variable X with a range > from 2 to 1024 and 4096 to 8192. > > X : Integer range (1 .. 1024) and (4096 .. 8192); > > or something similar to this declaration. in addition to define > non-consecutive ranges, could i define a range of odd numbers? even > numbers? Or in general numbers for which the arbitrarily complicated predicate P holds. If you put it this way, you see that the language has to define some more or less arbitrary cut off point on what is implemented as part of the fundamental syntax. In C, not even simple ranges make the cutoff. In Ada, simple ranges do, but not split ranges (or odd or even etc). In ABC, Lambert Meerten's teaching language, if I remember right, you can define arbitrary assertions that are associated with types. Any attempt to assign a value executes the assertion, and causes a run time failure if the assertion fails. That's actually quite a nice extension, which can be done as an attribute (and therefore is an "allowed" extension). type Odd_Integer is new Integer; procedure Check (X : Odd_Integer) is begin if X mod 2 = 1 then Raise_Exception (Constraint_Error'Identity, "even value assigned to Odd_Integer"); end if; end Check; for Odd_Integer'Domain_Check use Check; Then Domain_Check would be called whenever a value of type Odd_Integer was modified. Another formulation would be function Check (X : Odd_Integer) return Odd_Integer; which would have the opportunity of modifying the assigned value before the assignment. Thoughts? Useful feature? Silly bell and whistle? [Above my desk when working on SPITBOL was a large, very elaborate sign in caligrophy that said DO NOT EMBELLISH :-) ] Robert Dewar -----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own