QUIZ: To be or not to be (able to post) 
Author Message
 QUIZ: To be or not to be (able to post)

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



Fri, 17 Mar 2000 03:00:00 GMT  
 QUIZ: To be or not to be (able to post)


Quote:

>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

(818) 985-1271



Sat, 18 Mar 2000 03:00:00 GMT  
 QUIZ: To be or not to be (able to post)

: 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

--

Intermetrics, Inc.  Burlington, MA  USA



Sat, 18 Mar 2000 03:00:00 GMT  
 QUIZ: To be or not to be (able to post)

: 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
           -----------------------------------------------

Quote:
>>> 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



Mon, 20 Mar 2000 03:00:00 GMT  
 QUIZ: To be or not to be (able to post)

: ...
: :       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

--

Intermetrics, Inc.  Burlington, MA  USA



Mon, 20 Mar 2000 03:00:00 GMT  
 QUIZ: To be or not to be (able to post)

: 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



Mon, 20 Mar 2000 03:00:00 GMT  
 QUIZ: To be or not to be (able to post)



Quote:
>...  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



Tue, 21 Mar 2000 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. I am not able to read a barcode from a image

2. I am not able to execute new.ccf in coboldpc when I call coboldpc through labview

3. I am not deaf, but am I mute?

4. Urgent!!Oracle9i:using ODBC, I am noy able to link to my database tables using Access

5. I am not visible!!!!!

6. IDX not CDX - What am I missing

7. I am looking for drivers of Tektronix TDS694C, which are not available on website

8. Why I am not enthusiatic about OO COBOL

9. I am NOT a lawyer, ...

10. I am not a liar

11. No I am not D. Stamhope from ERG

12. Why I am not reaching callbacks ?

 

 
Powered by phpBB® Forum Software