comp.lang.ada
 help / color / mirror / Atom feed
* QUIZ: To be or not to be (able to post)
@ 1997-09-29  0:00 Geert Bosch
  1997-09-30  0:00 ` Tucker Taft
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Geert Bosch @ 1997-09-29  0:00 UTC (permalink / raw)



OK, here is a nice question for all you Ada experts out there.
Why isn't the code below not legal? Or is it? If so, why?

   with Ada.Numerics.Elementary_Functions;
   procedure Renaming is

      function Sin (F : Float) return Float;

      function Sin (X : Float'Base) return Float'Base
	 renames Ada.Numerics.Elementary_Functions.Sin;

   begin
      null;
   end Renaming;

What does your favorite compiler say? And the others? ;-)

Regards,
   Geert




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: QUIZ: To be or not to be (able to post)
  1997-09-29  0:00 QUIZ: To be or not to be (able to post) Geert Bosch
  1997-09-30  0:00 ` Tucker Taft
@ 1997-09-30  0:00 ` Matthew Heaney
  1997-10-02  0:00 ` Joel VanLaven
  2 siblings, 0 replies; 7+ messages in thread
From: Matthew Heaney @ 1997-09-30  0:00 UTC (permalink / raw)



In article <60n3dm$fhi$1@gonzo.sun3.iaf.nl>, Geert Bosch
<geert@gonzo.sun3.iaf.nl> wrote:

>OK, here is a nice question for all you Ada experts out there.
>Why isn't the code below not legal? Or is it? If so, why?
>
>   with Ada.Numerics.Elementary_Functions;
>   procedure Renaming is
>
>      function Sin (F : Float) return Float;
>
>      function Sin (X : Float'Base) return Float'Base
>         renames Ada.Numerics.Elementary_Functions.Sin;
>
>   begin
>      null;
>   end Renaming;

Isn't this a "co-resident homograph"?  Float is a subtype of Float'Base,
and subtypes can't be used to resolve ambiguity.  Only types are part of a
signiture, not subtypes.

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: QUIZ: To be or not to be (able to post)
  1997-09-29  0:00 QUIZ: To be or not to be (able to post) Geert Bosch
@ 1997-09-30  0:00 ` Tucker Taft
  1997-09-30  0:00 ` Matthew Heaney
  1997-10-02  0:00 ` Joel VanLaven
  2 siblings, 0 replies; 7+ messages in thread
From: Tucker Taft @ 1997-09-30  0:00 UTC (permalink / raw)



Geert Bosch (geert@gonzo.sun3.iaf.nl) wrote:

: OK, here is a nice question for all you Ada experts out there.
: Why isn't the code below not legal? Or is it? If so, why?

:    with Ada.Numerics.Elementary_Functions;
:    procedure Renaming is

:       function Sin (F : Float) return Float;

:       function Sin (X : Float'Base) return Float'Base
: 	 renames Ada.Numerics.Elementary_Functions.Sin;

This is not legal because you use "F" in the declaration of Sin
and you use "X" in the renaming-as-body, and that violates 8.5.4(5) which
requires full conformance of profiles between a renaming-as-body
and the declaration it completes.  

On the other hand, it is OK to use Float in one and Float'Base in the 
other because subtype Float statically matches subtype Float'Base.
They statically match because they are of the same type,
and they both have the "null" constraint.  See 4.9.1(2) and 3.5.7(12).

: ...
: What does your favorite compiler say? 

It complains as follows:

    6     function Sin (X : Float'Base) return Float'Base
                   *
*****Error: LRM:8.5.4(5) a renaming-as-body must be fully conformant with the
*****        declaration it completes, continuing
    7         renames Ada.Numerics.Elementary_Functions.Sin;

: ... And the others? ;-)

I haven't tried any others on this.

: Regards,
:    Geert

--
-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Burlington, MA  USA




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: QUIZ: To be or not to be (able to post)
  1997-10-02  0:00 ` Joel VanLaven
@ 1997-10-02  0:00   ` Tucker Taft
  1997-10-02  0:00     ` Joel VanLaven
  0 siblings, 1 reply; 7+ messages in thread
From: Tucker Taft @ 1997-10-02  0:00 UTC (permalink / raw)



Joel VanLaven (jvl@ocsystems.com) wrote:
: ...
: :       function Sin (F : Float) return Float;

: :       function Sin (X : Float'Base) return Float'Base
: : 	 renames Ada.Numerics.Elementary_Functions.Sin;
: ...
: Our compiler (PowerAda) says:

:      6:    function Sin (X : Float'Base) return Float'Base
:            -----------------------------------------------
: >>> SEMANTIC: Formal part of renaming-as-body is inconsistent with its
: specification <8.5.4:5>


: the LRM reference says (just the good part):
: "The profile of a renaming-as-body shall ..., and shall conform fully to that
: of the declaration it completes"

: Fully conformant includes subtype conformant and the two profiles are not
: subtype conformant.

Actually, they *are* subtype conformant, but they are not *fully* conformant
because of the formal parameter name change from F to X.  I bet your
compiler knew that already ;-).

: -- Joel VanLaven

--
-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Burlington, MA  USA




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: QUIZ: To be or not to be (able to post)
  1997-10-02  0:00   ` Tucker Taft
@ 1997-10-02  0:00     ` Joel VanLaven
  1997-10-03  0:00       ` Robert A Duff
  0 siblings, 1 reply; 7+ messages in thread
From: Joel VanLaven @ 1997-10-02  0:00 UTC (permalink / raw)



Tucker Taft <stt@houdini.camb.inmet.com> wrote:

: Actually, they *are* subtype conformant, but they are not *fully* conformant
: because of the formal parameter name change from F to X.  I bet your
: compiler knew that already ;-).

Sure enough, I goofed.  I tried compiling it with the X changed to an F and
it worked so our compiler must have "known that".  I am just a little
surprised that the "obvious" big difference (between float and float'base) 
wasn't really a difference at all.

Thanks for the catch.

-- Joel VanLaven




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: QUIZ: To be or not to be (able to post)
  1997-09-29  0:00 QUIZ: To be or not to be (able to post) Geert Bosch
  1997-09-30  0:00 ` Tucker Taft
  1997-09-30  0:00 ` Matthew Heaney
@ 1997-10-02  0:00 ` Joel VanLaven
  1997-10-02  0:00   ` Tucker Taft
  2 siblings, 1 reply; 7+ messages in thread
From: Joel VanLaven @ 1997-10-02  0:00 UTC (permalink / raw)



Geert Bosch <geert@gonzo.sun3.iaf.nl> wrote:
: OK, here is a nice question for all you Ada experts out there.
: Why isn't the code below not legal? Or is it? If so, why?

:    with Ada.Numerics.Elementary_Functions;
:    procedure Renaming is

:       function Sin (F : Float) return Float;

:       function Sin (X : Float'Base) return Float'Base
: 	 renames Ada.Numerics.Elementary_Functions.Sin;

:    begin
:       null;
:    end Renaming;

: What does your favorite compiler say? And the others? ;-)

Our compiler (PowerAda) says:

     6:    function Sin (X : Float'Base) return Float'Base
           -----------------------------------------------
>>> SEMANTIC: Formal part of renaming-as-body is inconsistent with its
specification <8.5.4:5>


the LRM reference says (just the good part):
"The profile of a renaming-as-body shall ..., and shall conform fully to that
of the declaration it completes"

Fully conformant includes subtype conformant and the two profiles are not
subtype conformant.

-- Joel VanLaven




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: QUIZ: To be or not to be (able to post)
  1997-10-02  0:00     ` Joel VanLaven
@ 1997-10-03  0:00       ` Robert A Duff
  0 siblings, 0 replies; 7+ messages in thread
From: Robert A Duff @ 1997-10-03  0:00 UTC (permalink / raw)



In article <6114h5$pmk@news3.his.com>,
Joel VanLaven  <jvl@ocsystems.com> wrote:
>...  I am just a little
>surprised that the "obvious" big difference (between float and float'base) 
>wasn't really a difference at all.

If you say:

    type T1 is range -10..10;
    type T2 is digits 5 range -10.0..10.0;

then T1 and T2 are constrained.  On the other hand, if you say:

    type T3 is digits 5; -- no range given here

then T3 is unconstrained.  So T3 is the same thing as T3'Base (both are
unconstrained).  But T1 and T1'Base are different, and T2 and T2'Base
are different (T1 and T2 are constrained; T1'Base and T2'Base are
unconstrained).

The predefined floating point types, such as Float, are like T3 in this
regard.  That is, Float is unconstrained, so Float is the same thing as
Float'Base.  This is because the declaration of Float has no "something
.. something else".  See A.1(20).

The predefined integer types, such as Integer, are constrained.

This all makes sense to me.  The "surprise" probably comes from the fact
that this is different from Ada 83, where the first subtype was always
constrained in the floating-point case.

- Bob




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~1997-10-03  0:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-09-29  0:00 QUIZ: To be or not to be (able to post) Geert Bosch
1997-09-30  0:00 ` Tucker Taft
1997-09-30  0:00 ` Matthew Heaney
1997-10-02  0:00 ` Joel VanLaven
1997-10-02  0:00   ` Tucker Taft
1997-10-02  0:00     ` Joel VanLaven
1997-10-03  0:00       ` Robert A Duff

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox