comp.lang.ada
 help / color / mirror / Atom feed
From: Ray Blaak <blaak@infomatch.com>
Subject: Tables vs functions (was Re: Anonymous array clarification.)
Date: 20 Aug 2001 09:49:39 -0700
Date: 2001-08-20T09:49:39-07:00	[thread overview]
Message-ID: <un14uy8v0.fsf_-_@infomatch.com> (raw)
In-Reply-To: 3b80c13f$1@pull.gecm.com

"Phil Thornley" <phil.thornley@baesystems.com> 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.



  reply	other threads:[~2001-08-20 16:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-20  6:18 Anonymous array clarification McDoobie
2001-08-20  8:03 ` Phil Thornley
2001-08-20 16:49   ` Ray Blaak [this message]
2001-08-20 17:28     ` Tables vs functions (was Re: Anonymous array clarification.) Marin David Condic
2001-08-20 21:02       ` Samuel T. Harris
2001-08-21 14:13         ` Marin David Condic
2001-08-20  8:29 ` Anonymous array clarification David C. Hoos, Sr.
2001-08-20 10:26 ` Larry Hazel
2001-08-20 13:37 ` Samuel T. Harris
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox