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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,689ab254fbb71c5 X-Google-Attributes: gid103376,public From: eachus@spectre.mitre.org (Robert I. Eachus) Subject: Re: Help on deciding a data type. Date: 1996/09/05 Message-ID: #1/1 X-Deja-AN: 178758841 references: <322C50E0.167E@sdrc.com> organization: The Mitre Corp., Bedford, MA. newsgroups: comp.lang.ada Date: 1996-09-05T00:00:00+00:00 List-Id: In article 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...