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.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,74a56083ffbe573d X-Google-Attributes: gid103376,public From: rgilbert@unconfigured.xvnews.domain (Bob Gilbert) Subject: Re: Zoo question Date: 1996/08/14 Message-ID: <4usdkl$fg6@zeus.orl.mmc.com>#1/1 X-Deja-AN: 174139217 references: <320F16B6.6944@lmtas.lmco.com> organization: The unconfigured xvnews people reply-to: rgilbert@unconfigured.xvnews.domain newsgroups: comp.lang.ada Date: 1996-08-14T00:00:00+00:00 List-Id: In article <320F16B6.6944@lmtas.lmco.com>, Ken Garlington writes: > Here's a little brain teaser we received recently. Assuming no typos or > other obvious syntax errors, will the Fill procedure work in Ada 83? > > package Zoo is > > type Animal_ID is range 1 .. 5; -- yes, an enumeration type might be > -- better, but it spoils the example! {snip} > Get_Next_Animal: begin -- look carefully at this code! > Next_Animal := Animal_ID'Succ(Next_Animal); > exception > when others => Next_Animal := Animal_ID'First; > end Get_Next_Animal; I assume that the tricky part is that the attribute 'Succ operates on the base type of Animal_ID, which is of type integer, and does not consider the constraint 1 .. 5 (although the attributes 'First and 'Last do). That is if Next_Animal := 5, then Animal_ID'succ(Next_Animal) would not raise an exception but would return the value 6. However, I would expect an exception to occur when attempting to assign the result back to Next_Animal, so the code would probably produce the expected result (or perhaps not?). Of course using an enumeration type for Animal_ID would avoid the confusion. Is this any different for Ada 95? -Bob