From: Ludovic Brenta <ludovic@ludovic-brenta.org>
Subject: Re: Is this a bug in Ada.Numerics?
Date: Sun, 21 Oct 2012 05:39:09 +0200
Date: 2012-10-21T05:39:09+02:00 [thread overview]
Message-ID: <87r4oscx42.fsf@ludovic-brenta.org> (raw)
In-Reply-To: 0360d84c-ef42-4107-b837-4063da273ad8@googlegroups.com
Leo Brewin <leo.brewin@internode.on.net> writes:
> But having digested your answer I'm still a bit confused (sorry). Here
> is the "procedure" version of the above package,
>
> with Ada.Numerics.Generic_Complex_Types;
> with Ada.Numerics.Generic_Complex_Elementary_Functions;
>
> procedure foo is
>
> type Real is digits 18;
>
> package Complex_Types is new
> Ada.Numerics.Generic_Complex_Types (Real);
>
> use foo.Complex_Types;
> subtype Complex is foo.Complex_Types.Complex;
>
> procedure bar (z : in out Complex);
>
> package Complex_Maths is new
> Ada.Numerics.Generic_Complex_Elementary_Functions (Complex_Types);
>
> procedure bar (z : in out Complex) is
> begin
> z := Complex'(Re(z),0.0);
> end bar;
>
> begin
> null;
> end foo;
>
> This does compile and yet (by my reading of your reply) the "use foo"
> and "subtype complex" lines should introduce two distinct versions of
> Complex and thus should produce a compiler error.
The difference is that, in the procedure, the subtype Foo.Complex is
declared in the immediate scope where Complex_Maths is declared, so it
hides Foo.Complex_Types.Complex, so there is no ambiguity anymore. You
get the same effect with the package if you move the declaration of
Complex_Maths to the package spec.
These rules are quite subtle and the error messages from GNAT less than
helpful. Maybe that's why Ada has a reputation for being "difficult to
learn".
--
Ludovic Brenta.
next prev parent reply other threads:[~2012-10-28 2:25 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-21 0:37 Is this a bug in Ada.Numerics? Leo Brewin
2012-10-21 1:54 ` Yannick Duchêne (Hibou57)
2012-10-21 2:39 ` Leo Brewin
2012-10-21 1:55 ` Ludovic Brenta
2012-10-21 2:32 ` Leo Brewin
2012-10-21 3:39 ` Ludovic Brenta [this message]
2012-10-21 3:54 ` Leo Brewin
2012-10-21 8:59 ` Georg Bauhaus
2012-10-23 15:48 ` Vincent Marciante
2012-10-23 22:52 ` Leo Brewin
2012-10-23 23:09 ` Jeffrey Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox