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,c7ea1cb7a2beb2ee X-Google-Attributes: gid103376,public From: Keith Thompson Subject: Re: Disallowing Pre-Defined Operations Date: 2000/03/09 Message-ID: #1/1 X-Deja-AN: 595501504 Sender: kst@king.cts.com References: <8a9eeg$qtv$1@newpoisson.nosc.mil> X-Trace: thoth.cts.com 952668990 84673 198.68.168.21 (10 Mar 2000 06:16:30 GMT) Organization: CTS Network Services Newsgroups: comp.lang.ada X-Complaints-To: newsmaster@cts.com Date: 2000-03-09T00:00:00+00:00 List-Id: claveman@cod.nosc.mil (Charles H. Sampson) writes: > During the deliberations that led to Ada 95, was a mechanism for > disallowing the pre-defined operations of a type considered? By "disal- > lowing" I mean some way of informing the compiler that an attempt to use > a certain pre-defined operation is a compile-time error. Did anyone > even ask for it? (Obviously I didn't, even though I've thought since > the mid-eighties that it would be a useful capability to have.) That seems like a good idea, but it would cause problems for generics. If you forbid "*" on a floating-point type, you can't use it to instantiate a generic that takes a floating-point formal type. This includes Float_IO (which very likely uses "*" and/or "/" internally). It also introduces some conceptual problems with the built-in attributes like 'Image and 'Value, though I suppose the language definition could just ignore these problems. It's too bad you can't define literals for a private type, but you can come close by overload the unary "+" operator. For example: type Time_Type is private; type Delta_Time_Type is private; function "-"(Left: Time_Type; Right: Time_Type) return Delta_Time_Type; function "-"(Left: Time_Type; Right: Delta_Time_Type) return Time_Type; -- other appropriate operations function "+"(Right: Float) return Time_Type; function "+"(Right: Float) return Delta_Time_Type; You can then use: T : Time_Type := +123.45; -- or whatever T_Minus_1 : Time_Type := T - (+1.0); I haven't tried compiling this, so I'm not certain it will actually work, and I may be missing some obvious flaw. -- Keith Thompson (The_Other_Keith) kst@cts.com San Diego Supercomputer Center <*> Welcome to the last year of the 20th century.