comp.lang.ada
 help / color / mirror / Atom feed
From: eachus@spectre.mitre.org (Robert I. Eachus)
Subject: Re: Help on deciding a data type.
Date: 1996/09/05
Date: 1996-09-05T00:00:00+00:00	[thread overview]
Message-ID: <EACHUS.96Sep5193850@spectre.mitre.org> (raw)
In-Reply-To: ytc20gicxob.fsf@erlang.praxis.co.uk


In article <ytc20gicxob.fsf@erlang.praxis.co.uk> sgb@erlang.praxis.co.uk (Stephen Bull) writes:

  > I would suggest defining a record type with two fields: the first is a flag
  > indicating whether the second is a valid value:

  > type T is record
  >   Valid : Boolean;
  >   Value : Symbol;
  > end record;

   There are two choices here.  The one I would recommend if
efficiency is an issue is to go through the pain of redefining all of
the operations in a generic package, then instantiating that package
for all moduli of interest.

   If however you want a simple, useable method that will never steer
you wrong try:

   type Real_Mod7 is mod 7;
   type Mod7 is access Mod7;

   Indeterminate: Mod7 := null;

   ...

   function "+" (L,R: Mod7) return Mod7 is
   begin
     return new Real_Mod7'(L.all + R.all);
   exception
     when others return Indeterminate;
   end "+";

   ...and so on.

   Notice that even on a garbage collecting Ada implementation you are
going to spend a lot of extra CPU cycles over a more sophisitcated
solution.  But you will get the correct answers.

--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




      reply	other threads:[~1996-09-05  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-09-03  0:00 Help on deciding a data type Sreedhar Chintalapaty
1996-09-04  0:00 ` Stephen Bull
1996-09-05  0:00   ` Robert I. Eachus [this message]
replies disabled

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