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,fc8cef2534e95561,start X-Google-Attributes: gid103376,public From: ok@goanna.cs.rmit.edu.au (Richard A. O'Keefe) Subject: 'Digit is generic package Date: 1996/08/23 Message-ID: <4vj3e6$hi1@goanna.cs.rmit.edu.au>#1/1 X-Deja-AN: 175952630 organization: Comp Sci, RMIT, Melbourne, Australia nntp-posting-user: ok newsgroups: comp.lang.ada summary: max precision of two generic formal types? Date: 1996-08-23T00:00:00+00:00 List-Id: Some time ago I posted a question but never saw a reply, so here it is again, in somewhat less detail. What I *want* to do is generic type Coord is digits <>; type Value is digits <>; package Foo_Pkg is type Number is digits Max(Coord'Digits, Value'Digits); ... end Foo_Pkg; I _could_ handle this by making Number a generic type too, and then checking that Number'Digits >= Coord'Digits and Number'Digits >= Value'Digits, but heck, I could use C++ or Fortran 90, or better still, Common Lisp. There is another rather horrible workaround that I just thought of, which could be used for a procedure, but not for a package: generic type Coord is digits <>; type Value is digits <>; type Number is digits <>; procedure Hidden_Foo(.....); generic type Coord is digits <>; type Value is digits <>; procedure Visible_Foo(...); procedure Visible_Foo(...) is procedure X is new Hidden_Foo(Coord, Value, Coord); procedure Y is new Hidden_Foo(Value, Coord, Coord); begin if Coord'Digits >= Value'Digits then X(...); else Y(...); end if; end Visible_Foo; but it's a bit like a Johnson's "dog walking on its hind legs". I have read the annotated Ada 95 RM carefully, and I know that when Gnat rejects the code I want to write it is doing exactly what the standard requires. Apart from the problem with Max, there is the unpleasant fact that Coord'Digits is not a static something-or-other expression, much to my surprise. This has the consequence, which I still find, um, quirky, that type Number is new Coord; is legal inside a generic package like this, but type Number is new digits Coord'Digits; is not. (a) I would get some consolation from knowing whether this was an *intended* restriction for Ada 95 and if so what harm would have resulted had this restriction not been in the language. (b) Is there any better approach for doing this with a procedure than the make-to-instances-and-pick-one-at-runtime one shown above? (c) Is there any reasonable approach for doing what I want with a package? For what it's worth, the least ugly and most robust workaround I could come up with was just to do type Number is new Long_Float; and comment it to say what I really want. -- Australian citizen since 14 August 1996. *Now* I can vote the xxxs out! Richard A. O'Keefe; http://www.cs.rmit.edu.au/~ok; RMIT Comp.Sci.