From: ok@goanna.cs.rmit.edu.au (Richard A. O'Keefe)
Subject: 'Digit is generic package
Date: 1996/08/23
Date: 1996-08-23T00:00:00+00:00 [thread overview]
Message-ID: <4vj3e6$hi1@goanna.cs.rmit.edu.au> (raw)
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.
next reply other threads:[~1996-08-23 0:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-08-23 0:00 Richard A. O'Keefe [this message]
1996-08-24 0:00 ` 'Digit is generic package Robert I. Eachus
1996-08-29 0:00 ` Robert A Duff
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox