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.4 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00 autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3467cec1612741de X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-08-20 10:35:03 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!psinet-eu-nl!psiuk-p4!uknet!psiuk-n!news.pace.co.uk!nh.pace.co.uk!not-for-mail From: "Marin David Condic" Newsgroups: comp.lang.ada Subject: Re: Tables vs functions (was Re: Anonymous array clarification.) Date: Mon, 20 Aug 2001 13:28:52 -0400 Organization: Posted on a server owned by Pace Micro Technology plc Message-ID: <9lrhcn$9lc$1@nh.pace.co.uk> References: <3b80c13f$1@pull.gecm.com> NNTP-Posting-Host: dhcp-200-133.miami.pace.co.uk X-Trace: nh.pace.co.uk 998328535 9900 136.170.200.133 (20 Aug 2001 17:28:55 GMT) X-Complaints-To: newsmaster@news.cam.pace.co.uk NNTP-Posting-Date: 20 Aug 2001 17:28:55 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Xref: archiver1.google.com comp.lang.ada:12134 Date: 2001-08-20T17:28:55+00:00 List-Id: Or as an alternative: > function Tomorrow(A_Day : in Day) return Day is > begin > return Day'Succ(A_Day); exception when Constraint_Error => return Day'First ; > end Tomorrow; There is, of course, going to be some debate about using exceptions for conditions you expect to happen. However, I'd point out that the code is a bit more brief and that in some implementations it might be (on the average) faster - for whatever that's worth. Its just an alternate implementation style. :-) Which would I personally use? I'd usually go with what you described. There may be occasional uses of the Constraint_Error trap in things I write of this nature - I'm partial to that technique when implementing saturated arithmetic. Dunno if there is any consensus that it should be one way or another in this case - but its a good one to put in a programming style guideline. Like formatting rules, I'd go with whatever the style guide recommends for a given project. MDC -- Marin David Condic Senior Software Engineer Pace Micro Technology Americas www.pacemicro.com Enabling the digital revolution e-Mail: marin.condic@pacemicro.com Web: http://www.mcondic.com/ "Ray Blaak" wrote in message news:un14uy8v0.fsf_-_@infomatch.com... > > Hmm. > > function Tomorrow(A_Day : in Day) return Day is > Result : Day; > begin > if A_Day < A_Day'Last then > Result := Day'Succ(A_Day); > else > Result := Day'First; > end if; > return Result; > end Tomorrow; > > Doesn't seem too complicated, looks the same to the user, is just as time > efficient, is more space efficient, and works for any size of > array/enumeration type. > > It also is more robust, since one does not have to tediously type out the > items in a possibly erroneous way. > > On the other hand, tables are useful when the calculations are expensive, > difficult or tedious to describe algorithmically, or the values change > according to subsequent data inputs. > > -- > Cheers, The Rhythm is around me, > The Rhythm has control. > Ray Blaak The Rhythm is inside me, > blaak@infomatch.com The Rhythm has my soul.