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 autolearn=ham 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 09:51:22 PST Path: archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newsfeed.bc.tac.net!news.bc.tac.net!not-for-mail Sender: blaak@TORUS Newsgroups: comp.lang.ada Subject: Tables vs functions (was Re: Anonymous array clarification.) References: <3b80c13f$1@pull.gecm.com> From: Ray Blaak Message-ID: Organization: The Transcend X-Newsreader: Gnus v5.7/Emacs 20.7 Date: 20 Aug 2001 09:49:39 -0700 NNTP-Posting-Host: 208.181.209.61 X-Complaints-To: news@bctel.net X-Trace: news.bc.tac.net 998326275 208.181.209.61 (Mon, 20 Aug 2001 09:51:15 PDT) NNTP-Posting-Date: Mon, 20 Aug 2001 09:51:15 PDT Xref: archiver1.google.com comp.lang.ada:12131 Date: 2001-08-20T09:49:39-07:00 List-Id: "Phil Thornley" writes: > On the question of what they are used for, I most commonly use them for > look-up tables. > > type Day is (Mon, Tue, Wed, Thu, Fri, Sat, Sun); > > Tomorrow : constant array (Day) of Day > := (Tue, Wed, Thu, Fri, Sat, Sun, Mon); > > (which avoids a lot of stuff about 'Succ and worrying about > wrap-around). 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.