Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

There *__is* no such thing as a civil engineer.


devel / comp.lang.ada / Re: overloading predefined operators

SubjectAuthor
* overloading predefined operatorsL. B.
+* Re: overloading predefined operatorsDmitry A. Kazakov
|+- Re: overloading predefined operatorsL. B.
|`* Re: overloading predefined operatorsRandy Brukardt
| `* Re: overloading predefined operatorsL. B.
|  `- Re: overloading predefined operatorsG.B.
`- Re: overloading predefined operatorsJeffrey R.Carter

1
overloading predefined operators

<1fabca7a-e3f0-41bb-9b51-9eabde85e800n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=7087&group=comp.lang.ada#7087

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:600c:19cf:b0:39c:88a0:c66e with SMTP id u15-20020a05600c19cf00b0039c88a0c66emr2284075wmq.37.1656058257954;
Fri, 24 Jun 2022 01:10:57 -0700 (PDT)
X-Received: by 2002:a0d:dfc3:0:b0:318:44f8:3c94 with SMTP id
i186-20020a0ddfc3000000b0031844f83c94mr14264822ywe.439.1656058257482; Fri, 24
Jun 2022 01:10:57 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.128.88.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Fri, 24 Jun 2022 01:10:57 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=87.143.123.42; posting-account=3zVVBwoAAAC7BSMfgNP7DSbqU9urpt40
NNTP-Posting-Host: 87.143.123.42
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <1fabca7a-e3f0-41bb-9b51-9eabde85e800n@googlegroups.com>
Subject: overloading predefined operators
From: mario.bl...@gmail.com (L. B.)
Injection-Date: Fri, 24 Jun 2022 08:10:57 +0000
Content-Type: text/plain; charset="UTF-8"
 by: L. B. - Fri, 24 Jun 2022 08:10 UTC

I have a question regarding redefining of operators like "=". My dummy code is:

type my_float is new float;

-- This overloads the predefined equality operation:
function "=" (left, right : in my_float) return boolean is begin
....
end "="

a, b : my_float;

a := 0.01
b := 0.009;

-- This test uses the overloading equality test:
if a = b then -- uses the new "="
null;
end if;

-- For some reasons I still need access to the overloaded original "=" function:
if a = b then -- shall use the original "="
null;
end if;

What can I do ?

Re: overloading predefined operators

<t93sak$10r4$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=7088&group=comp.lang.ada#7088

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!siG8trSPtxwtkBCOZpBn8A.user.46.165.242.91.POSTED!not-for-mail
From: mail...@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: overloading predefined operators
Date: Fri, 24 Jun 2022 10:23:48 +0200
Organization: Aioe.org NNTP Server
Message-ID: <t93sak$10r4$1@gioia.aioe.org>
References: <1fabca7a-e3f0-41bb-9b51-9eabde85e800n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="33636"; posting-host="siG8trSPtxwtkBCOZpBn8A.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.10.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Dmitry A. Kazakov - Fri, 24 Jun 2022 08:23 UTC

On 2022-06-24 10:10, L. B. wrote:
> I have a question regarding redefining of operators like "=". My dummy code is:
>
> type my_float is new float;
>
> -- This overloads the predefined equality operation:
> function "=" (left, right : in my_float) return boolean is begin
> ....
> end "="
>
> a, b : my_float;
>
> a := 0.01
> b := 0.009;
>
> -- This test uses the overloading equality test:
> if a = b then -- uses the new "="
> null;
> end if;
>
> -- For some reasons I still need access to the overloaded original "=" function:
> if a = b then -- shall use the original "="
> null;
> end if;
>
> What can I do ?

Rename the inherited operation before killing it:

type M_Float is new Float;
function Equal (Left, Right : M_Float) return Boolean renames "=";
function "=" (Left, Right : M_Float) return Boolean;

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

Re: overloading predefined operators

<46b00e1b-834c-41f1-b980-e1670301abafn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=7089&group=comp.lang.ada#7089

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:adf:fb10:0:b0:207:af88:1eb9 with SMTP id c16-20020adffb10000000b00207af881eb9mr12712329wrr.238.1656063884206;
Fri, 24 Jun 2022 02:44:44 -0700 (PDT)
X-Received: by 2002:a25:d790:0:b0:668:b0e3:9033 with SMTP id
o138-20020a25d790000000b00668b0e39033mr14276167ybg.493.1656063883608; Fri, 24
Jun 2022 02:44:43 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.mixmin.net!proxad.net!feeder1-2.proxad.net!209.85.128.88.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Fri, 24 Jun 2022 02:44:43 -0700 (PDT)
In-Reply-To: <t93sak$10r4$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=87.143.123.42; posting-account=3zVVBwoAAAC7BSMfgNP7DSbqU9urpt40
NNTP-Posting-Host: 87.143.123.42
References: <1fabca7a-e3f0-41bb-9b51-9eabde85e800n@googlegroups.com> <t93sak$10r4$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <46b00e1b-834c-41f1-b980-e1670301abafn@googlegroups.com>
Subject: Re: overloading predefined operators
From: mario.bl...@gmail.com (L. B.)
Injection-Date: Fri, 24 Jun 2022 09:44:44 +0000
Content-Type: text/plain; charset="UTF-8"
 by: L. B. - Fri, 24 Jun 2022 09:44 UTC

Great. Thank you !!!

Re: overloading predefined operators

<t944ne$us7$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=7090&group=comp.lang.ada#7090

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: spam.jrc...@spam.acm.org.not (Jeffrey R.Carter)
Newsgroups: comp.lang.ada
Subject: Re: overloading predefined operators
Date: Fri, 24 Jun 2022 12:47:10 +0200
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <t944ne$us7$1@dont-email.me>
References: <1fabca7a-e3f0-41bb-9b51-9eabde85e800n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 24 Jun 2022 10:47:11 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="7c8f46217bcc95c4aaa9ec976d5d557c";
logging-data="31623"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18wPYd5T0NNN3RP0w3BVw3c2MnhJXv5VQM="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Cancel-Lock: sha1:oEvt9ReHKe6FzTf3LfV3ZFQsbNA=
In-Reply-To: <1fabca7a-e3f0-41bb-9b51-9eabde85e800n@googlegroups.com>
Content-Language: en-US
 by: Jeffrey R.Carter - Fri, 24 Jun 2022 10:47 UTC

On 2022-06-24 10:10, L. B. wrote:
>
> type my_float is new float;
>
> function "=" (left, right : in my_float) return boolean is begin
> ....
> end "="
>
> a, b : my_float;
>
> a := 0.01
> b := 0.009;
>
> -- For some reasons I still need access to the overloaded original "=" function:
> if a = b then -- shall use the original "="
> null;
> end if;
>
> What can I do ?

With a derived type like this, you can convert back to the parent type:

if Float (A) = Float (B) then

With a completely new type, you can only name one of the operations "=". You
have to decide which one you want to call "=", and which one you want to call
something else, like Equal. So, for

type Real is digits 7;

you can either call your new operation Equal

function Equal (Left : in Real; Right : in Real) return Boolean;

which leave "=" for the predefined operation, or you can rename the predefined
operation to Equal as Kazakov has described

function Equal (Left : in Real; Right : in Real) return Boolean renames "=";
function "=" (Left : in Real; Right : in Real) return Boolean;

--
Jeff Carter
"[I]t is foolish to polish a program beyond the
point of diminishing returns, but most programmers
do too little revision; they are satisfied too
early."
Elements of Programming Style
189

Re: overloading predefined operators

<t95uqf$fu9$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=7092&group=comp.lang.ada#7092

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ran...@rrsoftware.com (Randy Brukardt)
Newsgroups: comp.lang.ada
Subject: Re: overloading predefined operators
Date: Fri, 24 Jun 2022 22:18:37 -0500
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <t95uqf$fu9$1@dont-email.me>
References: <1fabca7a-e3f0-41bb-9b51-9eabde85e800n@googlegroups.com> <t93sak$10r4$1@gioia.aioe.org>
Injection-Date: Sat, 25 Jun 2022 03:18:39 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ea8ee915547ce677c25b93936a1e0f4c";
logging-data="16329"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+bbRaxNSYKXr4sUPil1jaWxFkT7ujhb1Y="
Cancel-Lock: sha1:xFWes+eGJxnc844y0uPiev/Np58=
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246
X-RFC2646: Format=Flowed; Response
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
X-Priority: 3
X-MSMail-Priority: Normal
 by: Randy Brukardt - Sat, 25 Jun 2022 03:18 UTC

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
news:t93sak$10r4$1@gioia.aioe.org...
> On 2022-06-24 10:10, L. B. wrote:
>> I have a question regarding redefining of operators like "=". My dummy
>> code is:
>>
>> type my_float is new float;
>>
>> -- This overloads the predefined equality operation:
>> function "=" (left, right : in my_float) return boolean is begin
>> ....
>> end "="
>>
>> a, b : my_float;
>>
>> a := 0.01
>> b := 0.009;
>>
>> -- This test uses the overloading equality test:
>> if a = b then -- uses the new "="
>> null;
>> end if;
>>
>> -- For some reasons I still need access to the overloaded original "="
>> function:
>> if a = b then -- shall use the original "="
>> null;
>> end if;
>>
>> What can I do ?
>
> Rename the inherited operation before killing it:
>
> type M_Float is new Float;
> function Equal (Left, Right : M_Float) return Boolean renames "=";
> function "=" (Left, Right : M_Float) return Boolean;

This was important enough to the Ada 95 team that they gave it a name -- "a
squirreling rename" (as in "squirreling away"). You'll find that in the
index of the AARM to this day.

There's actually some special rules which allow this rename in cases where
without those rules you wouldn't be able to do this. It's important in some
cases

I generally prefer to use prefix notation in such cases rather than renaming
(which is easy to get subtly wrong). Remember that you can call any Ada
operator as if it is a normal function. So:

if Standard."=" (A, B) then

gives you the original "=" (which is defined in Standard for
Standard.Float).

Randy.

Re: overloading predefined operators

<eb55c39b-0d83-4c2a-be0a-0b62d30864c3n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=7093&group=comp.lang.ada#7093

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:6000:695:b0:21a:3a1a:7b60 with SMTP id bo21-20020a056000069500b0021a3a1a7b60mr2243061wrb.441.1656136721615;
Fri, 24 Jun 2022 22:58:41 -0700 (PDT)
X-Received: by 2002:a0d:ebc4:0:b0:318:31c1:be92 with SMTP id
u187-20020a0debc4000000b0031831c1be92mr2950575ywe.422.1656136721092; Fri, 24
Jun 2022 22:58:41 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.128.87.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Fri, 24 Jun 2022 22:58:40 -0700 (PDT)
In-Reply-To: <t95uqf$fu9$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=87.143.123.42; posting-account=3zVVBwoAAAC7BSMfgNP7DSbqU9urpt40
NNTP-Posting-Host: 87.143.123.42
References: <1fabca7a-e3f0-41bb-9b51-9eabde85e800n@googlegroups.com>
<t93sak$10r4$1@gioia.aioe.org> <t95uqf$fu9$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <eb55c39b-0d83-4c2a-be0a-0b62d30864c3n@googlegroups.com>
Subject: Re: overloading predefined operators
From: mario.bl...@gmail.com (L. B.)
Injection-Date: Sat, 25 Jun 2022 05:58:41 +0000
Content-Type: text/plain; charset="UTF-8"
 by: L. B. - Sat, 25 Jun 2022 05:58 UTC

Randy,

> I generally prefer to use prefix notation in such cases rather than renaming
> (which is easy to get subtly wrong). Remember that you can call any Ada
> operator as if it is a normal function. So:
>
> if Standard."=" (A, B) then

I tried this in
https://github.com/Blunk-electronic/ada_training/blob/master/src/redefining/equality_1/equality.adb
see line 99.

The compiler says:
equality.adb:99:20: incompatible arguments for operator

Re: overloading predefined operators

<t969hd$3eg$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=7094&group=comp.lang.ada#7094

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bauh...@notmyhomepage.invalid (G.B.)
Newsgroups: comp.lang.ada
Subject: Re: overloading predefined operators
Date: Sat, 25 Jun 2022 08:21:33 +0200
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <t969hd$3eg$1@dont-email.me>
References: <1fabca7a-e3f0-41bb-9b51-9eabde85e800n@googlegroups.com>
<t93sak$10r4$1@gioia.aioe.org> <t95uqf$fu9$1@dont-email.me>
<eb55c39b-0d83-4c2a-be0a-0b62d30864c3n@googlegroups.com>
Reply-To: nonlegitur@notmyhomepage.de
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 25 Jun 2022 06:21:33 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f993db08ecda2d93a44b0b761c64ae5e";
logging-data="3536"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18THbr9hsDlIPo7W+ylPAHkvFbZU4K1Utw="
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0)
Gecko/20100101 Thunderbird/91.10.0
Cancel-Lock: sha1:yudMaba5t0ivJqaZXcBlz3QWtbk=
In-Reply-To: <eb55c39b-0d83-4c2a-be0a-0b62d30864c3n@googlegroups.com>
Content-Language: en-US
 by: G.B. - Sat, 25 Jun 2022 06:21 UTC

On 25.06.22 07:58, L. B. wrote:
> Randy,
>
>> I generally prefer to use prefix notation in such cases rather than renaming
>> (which is easy to get subtly wrong). Remember that you can call any Ada
>> operator as if it is a normal function. So:
>>
>> if Standard."=" (A, B) then
>
> I tried this in
> https://github.com/Blunk-electronic/ada_training/blob/master/src/redefining/equality_1/equality.adb
> see line 99.
>
> The compiler says:
> equality.adb:99:20: incompatible arguments for operator

That's the compiler telling you that TYPE_FLOAT is not
type Float, the type of arguments needed for Standard."="
(see above).

See Jeffrey Carter's response for what to do to make them
that.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor