comp.lang.ada
 help / color / mirror / Atom feed
* overloading operators
@ 2018-11-21  9:56 hnptz
  2018-11-21 11:28 ` Jeffrey R. Carter
  2018-11-21 13:50 ` AdaMagica
  0 siblings, 2 replies; 11+ messages in thread
From: hnptz @ 2018-11-21  9:56 UTC (permalink / raw)


How can I use the old and the overloaded operator at the same time in the same program for the same type?
For example: Overloaded  "*" defined by user for type Real_Matrix and "*" defined in package Numerics.Real_Arrays for Real_Matrix.


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

* Re: overloading operators
  2018-11-21  9:56 overloading operators hnptz
@ 2018-11-21 11:28 ` Jeffrey R. Carter
  2018-11-21 13:50 ` AdaMagica
  1 sibling, 0 replies; 11+ messages in thread
From: Jeffrey R. Carter @ 2018-11-21 11:28 UTC (permalink / raw)


On 11/21/18 10:56 AM, hnptz@yahoo.de wrote:
> How can I use the old and the overloaded operator at the same time in the same program for the same type?
> For example: Overloaded  "*" defined by user for type Real_Matrix and "*" defined in package Numerics.Real_Arrays for Real_Matrix.

One can use Numerics.Real_Arrays."*" to refer to the "*" defined in 
Numerics.Real_Arrays.

-- 
Jeff Carter
"I certainly have not the talent which some people possess, ...
of conversing easily with those I have never seen before."
Pride and Prejudice
121


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

* Re: overloading operators
  2018-11-21  9:56 overloading operators hnptz
  2018-11-21 11:28 ` Jeffrey R. Carter
@ 2018-11-21 13:50 ` AdaMagica
  2018-11-21 13:52   ` AdaMagica
  2018-11-21 16:39   ` hnptz
  1 sibling, 2 replies; 11+ messages in thread
From: AdaMagica @ 2018-11-21 13:50 UTC (permalink / raw)


Am Mittwoch, 21. November 2018 10:56:09 UTC+1 schrieb hn...@yahoo.de:
> How can I use the old and the overloaded operator at the same time in the same program for the same type?
> For example: Overloaded  "*" defined by user for type Real_Matrix and "*" defined in package Numerics.Real_Arrays for Real_Matrix.

For the nomenclature:
If I understand correctly what you're saying, it's not overloading, but overriding what you're doing.
If you defined a function "*" for type Real_Matrix in a package of your own, say Pack, the corresponding operation in the package where Real_Matrix is defined, here Ada.Numerics, is hidden from direct and use visibility in Pack. You can make it visible again via an extended name.
So which "*" is visible at certain place depends on the kind of visibility of Pack and Ada.Numerics. With proper name qualification, both are callable at the same place in code.


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

* Re: overloading operators
  2018-11-21 13:50 ` AdaMagica
@ 2018-11-21 13:52   ` AdaMagica
  2018-11-21 16:39   ` hnptz
  1 sibling, 0 replies; 11+ messages in thread
From: AdaMagica @ 2018-11-21 13:52 UTC (permalink / raw)


And you can even squirrel away the old name before overriding.

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

* Re: overloading operators
  2018-11-21 13:50 ` AdaMagica
  2018-11-21 13:52   ` AdaMagica
@ 2018-11-21 16:39   ` hnptz
  2018-11-21 17:37     ` Simon Wright
  1 sibling, 1 reply; 11+ messages in thread
From: hnptz @ 2018-11-21 16:39 UTC (permalink / raw)


On Wednesday, November 21, 2018 at 2:50:05 PM UTC+1, AdaMagica wrote:
> Am Mittwoch, 21. November 2018 10:56:09 UTC+1 schrieb hn...@yahoo.de:
> > How can I use the old and the overloaded operator at the same time in the same program for the same type?
> > For example: Overloaded  "*" defined by user for type Real_Matrix and "*" defined in package Numerics.Real_Arrays for Real_Matrix.
> 
> For the nomenclature:
> If I understand correctly what you're saying, it's not overloading, but overriding what you're doing.
> If you defined a function "*" for type Real_Matrix in a package of your own, say Pack, the corresponding operation in the package where Real_Matrix is defined, here Ada.Numerics, is hidden from direct and use visibility in Pack. You can make it visible again via an extended name.
> So which "*" is visible at certain place depends on the kind of visibility of Pack and Ada.Numerics. With proper name qualification, both are callable at the same place in code.


what would be a proper name qualification? Extended name for pack defined "*" in Ada.Numerics like pack."*"?

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

* Re: overloading operators
  2018-11-21 16:39   ` hnptz
@ 2018-11-21 17:37     ` Simon Wright
  2018-11-22  8:18       ` briot.emmanuel
  0 siblings, 1 reply; 11+ messages in thread
From: Simon Wright @ 2018-11-21 17:37 UTC (permalink / raw)


hnptz@yahoo.de writes:

> On Wednesday, November 21, 2018 at 2:50:05 PM UTC+1, AdaMagica wrote:
>> Am Mittwoch, 21. November 2018 10:56:09 UTC+1 schrieb hn...@yahoo.de:
>> > How can I use the old and the overloaded operator at the same time
>> > in the same program for the same type?
>> > For example: Overloaded "*" defined by user for type Real_Matrix
>> > and "*" defined in package Numerics.Real_Arrays for Real_Matrix.
>> 
>> For the nomenclature:
>> If I understand correctly what you're saying, it's not overloading,
>> but overriding what you're doing.
>> If you defined a function "*" for type Real_Matrix in a package of
>> your own, say Pack, the corresponding operation in the package where
>> Real_Matrix is defined, here Ada.Numerics, is hidden from direct and
>> use visibility in Pack. You can make it visible again via an
>> extended name.
>> So which "*" is visible at certain place depends on the kind of
>> visibility of Pack and Ada.Numerics. With proper name qualification,
>> both are callable at the same place in code.
>
> what would be a proper name qualification? Extended name for pack
> defined "*" in Ada.Numerics like pack."*"?

You can always say e.g. Ada.Numerics.Real_Arrays."*" (A, B) but it is
rather clumsy compared to A * B!


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

* Re: overloading operators
  2018-11-21 17:37     ` Simon Wright
@ 2018-11-22  8:18       ` briot.emmanuel
  2018-11-22 11:39         ` Simon Wright
  2018-11-26 17:47         ` Anh Vo
  0 siblings, 2 replies; 11+ messages in thread
From: briot.emmanuel @ 2018-11-22  8:18 UTC (permalink / raw)


> You can always say e.g. Ada.Numerics.Real_Arrays."*" (A, B) but it is
> rather clumsy compared to A * B!


The main use I have for that notation is in expression functions in specs,
since we try to avoid use clauses in specs. So for instance:

    function Greater (A, B : Some_Package.My_Type)  return Some_Package.My_Type
        is (Some_Package.">" (A, B));


       

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

* Re: overloading operators
  2018-11-22  8:18       ` briot.emmanuel
@ 2018-11-22 11:39         ` Simon Wright
  2018-11-26 17:47         ` Anh Vo
  1 sibling, 0 replies; 11+ messages in thread
From: Simon Wright @ 2018-11-22 11:39 UTC (permalink / raw)


briot.emmanuel@gmail.com writes:

>> You can always say e.g. Ada.Numerics.Real_Arrays."*" (A, B) but it is
>> rather clumsy compared to A * B!
>
> The main use I have for that notation is in expression functions in specs,
> since we try to avoid use clauses in specs. So for instance:
>
>     function Greater (A, B : Some_Package.My_Type)  return Some_Package.My_Type
>         is (Some_Package.">" (A, B));

Good point (though return Boolean would be better :-)

Personally I try to avoid use clauses in body context clauses, too.

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

* Re: overloading operators
  2018-11-22  8:18       ` briot.emmanuel
  2018-11-22 11:39         ` Simon Wright
@ 2018-11-26 17:47         ` Anh Vo
  2018-11-26 18:03           ` Simon Wright
  1 sibling, 1 reply; 11+ messages in thread
From: Anh Vo @ 2018-11-26 17:47 UTC (permalink / raw)


On Thursday, November 22, 2018 at 12:18:06 AM UTC-8, briot.e...@gmail.com wrote:
> > You can always say e.g. Ada.Numerics.Real_Arrays."*" (A, B) but it is
> > rather clumsy compared to A * B!
> 
> 
> The main use I have for that notation is in expression functions in specs,
> since we try to avoid use clauses in specs. So for instance:
> 
>     function Greater (A, B : Some_Package.My_Type)  return Some_Package.My_Type
>         is (Some_Package.">" (A, B));

What is wrong with "use type clause"?

Anh Vo


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

* Re: overloading operators
  2018-11-26 17:47         ` Anh Vo
@ 2018-11-26 18:03           ` Simon Wright
  2018-11-26 18:24             ` Dmitry A. Kazakov
  0 siblings, 1 reply; 11+ messages in thread
From: Simon Wright @ 2018-11-26 18:03 UTC (permalink / raw)


Anh Vo <anhvofrcaus@gmail.com> writes:

> On Thursday, November 22, 2018 at 12:18:06 AM UTC-8, briot.e...@gmail.com wrote:
>> > You can always say e.g. Ada.Numerics.Real_Arrays."*" (A, B) but it is
>> > rather clumsy compared to A * B!
>> 
>> 
>> The main use I have for that notation is in expression functions in specs,
>> since we try to avoid use clauses in specs. So for instance:
>> 
>>     function Greater (A, B : Some_Package.My_Type)  return Some_Package.My_Type
>>         is (Some_Package.">" (A, B));
>
> What is wrong with "use type clause"?

Nothing, but OP was asking about what qualifications are available

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

* Re: overloading operators
  2018-11-26 18:03           ` Simon Wright
@ 2018-11-26 18:24             ` Dmitry A. Kazakov
  0 siblings, 0 replies; 11+ messages in thread
From: Dmitry A. Kazakov @ 2018-11-26 18:24 UTC (permalink / raw)


On 2018-11-26 19:03, Simon Wright wrote:
> Anh Vo <anhvofrcaus@gmail.com> writes:
> 
>> On Thursday, November 22, 2018 at 12:18:06 AM UTC-8, briot.e...@gmail.com wrote:
>>>> You can always say e.g. Ada.Numerics.Real_Arrays."*" (A, B) but it is
>>>> rather clumsy compared to A * B!
>>>
>>>
>>> The main use I have for that notation is in expression functions in specs,
>>> since we try to avoid use clauses in specs. So for instance:
>>>
>>>      function Greater (A, B : Some_Package.My_Type)  return Some_Package.My_Type
>>>          is (Some_Package.">" (A, B));
>>
>> What is wrong with "use type clause"?
> 
> Nothing, but OP was asking about what qualifications are available

Then I think one forgot qualification of the arguments:

   ...
   is (Some_Package.">" (Some_Package.Greater.A, Some_Package.Greater.B));

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


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

end of thread, other threads:[~2018-11-26 18:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-21  9:56 overloading operators hnptz
2018-11-21 11:28 ` Jeffrey R. Carter
2018-11-21 13:50 ` AdaMagica
2018-11-21 13:52   ` AdaMagica
2018-11-21 16:39   ` hnptz
2018-11-21 17:37     ` Simon Wright
2018-11-22  8:18       ` briot.emmanuel
2018-11-22 11:39         ` Simon Wright
2018-11-26 17:47         ` Anh Vo
2018-11-26 18:03           ` Simon Wright
2018-11-26 18:24             ` Dmitry A. Kazakov

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