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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,73cb216d191f0fef X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit X-Received: by 10.224.87.2 with SMTP id u2mr9628731qal.4.1363034503786; Mon, 11 Mar 2013 13:41:43 -0700 (PDT) X-Received: by 10.50.214.36 with SMTP id nx4mr1369141igc.6.1363034503554; Mon, 11 Mar 2013 13:41:43 -0700 (PDT) Path: o5ni743qas.0!nntp.google.com!dd2no788696qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 11 Mar 2013 13:41:43 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=69.20.190.126; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 69.20.190.126 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Is this expected behavior or not From: Shark8 Injection-Date: Mon, 11 Mar 2013 20:41:43 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2013-03-11T13:41:43-07:00 List-Id: On Monday, March 11, 2013 2:01:04 PM UTC-6, Robert A Duff wrote: > Anh Vo writes: >=20 > > I have read ARM section 3.2.4, Subtype Predicates, I did not see any > > rules prohibiting from using attribute 'Succ as contained in the code > > nipet below. I would expect Prime'Succ (3) return 5 for next prime > > number. However, 4 is returned instead. Is this a correct behavior? >=20 > It is standard-conforming behavior. Prime'Succ is the same as > Prime'Base'Succ. Many other attributes behave the same way. > This has been true since Ada 83. For example, Prime'Succ(1000) =3D 1001, > and does not raise an exception. This is something that is especially useful: consider the instance where yo= u are slicing out portions of an array, say parsing out a STRING:VALUE sort= of construction or doing some [certain] linear combinations: Key : Constant String :=3D Get_Part( Element, Before ); Val : Constant String :=3D Get_Part( Element, After ); -- Where Get_Part is: Type Portion is ( Before, After ); Function Get_Part( Item : String; Part : Portion ) Return String is Use Ada.Strings.Fixed; Pos : Constant Natural :=3D Index( Source =3D> Item, Pattern =3D> "" & Seperator ); SubType Head is Positive Range Item'First..Integer'Pred(Pos); SubType Tail is Positive Range Positive'Succ(Pos)..Item'Last; Begin Return (if Part =3D Before then Item(Head) else Item(Tail)); End Get_Part; We don't want the subtype "Head" to fail when the Pred'(Pos) is applied [an= d Pos =3D 1] while declaring the range; this precisely because the null-ran= ge is valid and what we desire. The construction of range 1..0 should there= fore not generate an exception despite 0 not being a member of Positive.