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,ae5e339df4dff313 X-Google-Attributes: gid103376,public From: Robert A Duff Subject: Re: Language Lawyer question Date: 2000/06/05 Message-ID: #1/1 X-Deja-AN: 631329933 Sender: bobduff@world.std.com (Robert A Duff) References: <39380CEB.2CC4682E@ftw.rsc.raytheon.com> <8h97q3$68b$1@hobbes2.crc.com> Organization: The World Public Access UNIX, Brookline, MA Newsgroups: comp.lang.ada Date: 2000-06-05T00:00:00+00:00 List-Id: "David C. Hoos, Sr." writes: > What is 0'Pred? It depends on context, just like any other overload resolution question. If that were legal, then we could write: X: Integer; type Modular is mod 123; Y: Modular; X := (0)'Pred; Y := (0)'Pred; and they would resolve to the appropriate type, just as if you had written something like "X := -(0);" Or, for that matter, "X := 0;". In the rare cases where context doesn't determine the type already, you use a qualified expression: if 0'Pred = -1 then -- Ambiguous; illegal. if Integer'((0)'Pred) = -1 then -- OK if (Integer'(0)'Pred) = -1 then -- OK if (0)'Pred = Integer'(-1) then -- OK > 1. Illegal if Natural > 2. -1 if Integer Well, Natural and Integer are the same *type*, which is all overload resolution cares about. Also, Integer'Pred and Natural'Pred are the same -- Natural'Pred(0) is legal, and does not raise any exception -- it returns -1. So, presumably if (0)'Pred were legal syntax, it would do the same thing. > 3, 2 ** modulus - 1 if modular > > Now if you meant Some_Object'Pred -- that's possible > > But, how would you do the equivalent of Modular_Type'Pred (0) > with your syntax? See above -- the same way you deal with overloaded operators applied to literals. To answer the original question: There is no very good reason why it's T'Pred(X) rather than X'Pred. The syntax could be redesigned to allow attributes applied to expressions (although as Robert Eachus pointed out in another note, it's tricky to get that right), and overload resolution could be used in the normal way to resolve these things. I suspect the real reason is simply that the original language designers didn't like that style -- a matter of taste. Here's a related question: Why can't I say: subtype Digit is range 0..9; function To_Character(X: Digit) return Character is begin return (String'("0123456789"))(X+1); -- Illegal. end To_Character; ? - Bob