comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <rieachus@comcast.net>
Subject: Re: Negative float problem
Date: Thu, 27 Oct 2005 04:05:07 -0400
Date: 2005-10-27T04:05:07-04:00	[thread overview]
Message-ID: <NI-dnTOLqY64F_3eRVn-uQ@comcast.com> (raw)
In-Reply-To: <wccmzkwqabg.fsf@shell01.TheWorld.com>

Robert A Duff wrote:

> But I suggest using the first solution.  Really, the "use type"
> semantics ought to be turned on by default -- you shouldn't have to say
> anything special to use the "-" operator.  After all, you don't have
> to say anything special to use "1.0" or ":=" on this type!

There was an Ada83 AI on this, usually referred to as the "for I in 
1..-10" problem.  (Yes the loop would be executed zero times, but the 
problem is that an Ada 83 compiler was required to reject the for 
statement.)  Tucker came up with some preference rules that handle some 
of the cases, but the case mentioned here is one of the more refractory 
ones.  It could be solved by having a negation symbol that could be part 
of a numeric literal.  But as long as users are allowed to overload 
operator symbols, the visibility rules will have some edge cases like 
this one.

For example

package file1 is

	type My_Float is digits 6;
         function "-"(L: My_Float) return My_Float;
end file1;

package body file1 is
         function "-"(L: My_Float) return My_Float is
         begin return L-1.0; end "-";
end file1;

with file1; use file1;
with Ada.Text_IO; use Ada.Text_IO;
procedure file2 is
	X : file1.My_Float := -1.0;
         function "-"(L: My_Float) return My_Float is
         begin return L+1.0; end "-";
         Y : file1.My_Float := -1.0;
begin
         if X /= Y then Put_Line("Correct"); end if;
end file2;

f:\Ada>gnatmake file2
gnatmake file2
gcc -c file2.adb
gcc -c file1.adb
gnatbind -x file2.ali
gnatlink file2.ali

f:\Ada>file2
file2
Correct

Now in one sense this is a pretty silly example.  But it is the way the 
visibility and overloading rules work in Ada for good reasons that have 
nothing to do with this example. ;-)  Obviously it is better to have one 
set of visibility rules for all subprograms than for programmers to try 
to remember which set of visibility rules apply in this case.  (Yes, 
there is a different set of rules for basic operations like numeric 
literals and assignment.  But since these are not overloadable, this 
doesn't cause a problem.)

Finally, there is actually a third way to make the negation operator 
from file1 visible.  But note that this is direct visibility not use 
visible:
   function "-"(L: My_Float) return My_Float renames file1."-";



  reply	other threads:[~2005-10-27  8:05 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-26 18:32 Negative float problem Luke
2005-10-26 19:05 ` Samuel Tardieu
2005-10-26 20:42 ` Robert A Duff
2005-10-27  8:05   ` Robert I. Eachus [this message]
2005-10-27 14:48     ` Robert A Duff
2005-10-27 15:07       ` Maciej Sobczak
2005-10-27 15:47         ` Robert A Duff
2005-10-28  8:34           ` Maciej Sobczak
2005-10-29 23:39             ` Brian May
2005-10-30  9:11             ` Dmitry A. Kazakov
2005-10-31  9:46               ` Maciej Sobczak
2005-10-31 14:20                 ` Dmitry A. Kazakov
2005-11-01 11:06                   ` Maciej Sobczak
2005-11-01 14:06                     ` Robert A Duff
2005-11-01 14:46                       ` Martin Dowie
2005-11-01 16:04                         ` Hyman Rosen
2005-11-01 17:19                           ` Martin Dowie
2005-11-02  0:13                         ` Robert A Duff
2005-11-02  6:59                           ` Martin Dowie
2005-11-02 13:24                             ` Robert A Duff
2005-11-02 15:22                               ` Martin Dowie
2005-11-01 15:12                       ` Maciej Sobczak
2005-11-02  0:28                         ` Robert A Duff
2005-11-02  4:16                           ` Steve Whalen
2005-11-14  7:26                           ` Dave Thompson
2005-11-20  0:19                             ` Robert A Duff
2005-11-20 11:07                               ` Dmitry A. Kazakov
2005-11-01 14:27                     ` Dmitry A. Kazakov
2005-11-01 15:19                       ` Maciej Sobczak
2005-11-01 19:44                         ` Dmitry A. Kazakov
2005-11-02  9:04                           ` Maciej Sobczak
2005-11-02 11:17                             ` Dmitry A. Kazakov
2005-11-02 13:03                               ` Maciej Sobczak
2005-11-02 14:20                                 ` Jean-Pierre Rosen
2005-11-02 20:15                                   ` Jeffrey R. Carter
2005-11-03 13:06                                     ` Jean-Pierre Rosen
2005-11-03 18:32                                       ` Jeffrey R. Carter
2005-11-03  9:51                                   ` Maciej Sobczak
2005-11-03 13:20                                     ` Jean-Pierre Rosen
2005-11-03 15:02                                       ` Maciej Sobczak
2005-11-03 18:55                                         ` Frank J. Lhota
2005-11-04  9:32                                           ` Maciej Sobczak
2005-11-03 20:59                                     ` Simon Wright
2005-11-02 13:32                               ` Robert A Duff
2005-11-02 14:44                                 ` Dmitry A. Kazakov
2005-11-02 13:47                               ` Dmitry A. Kazakov
2005-10-27 18:33       ` Dmitry A. Kazakov
replies disabled

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