Compound assignment for logic operators

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Compound assignment for logic operators

paulk_asert

Hi Everyone,

I noticed that the '&&=' and '||=' operators (LOGICAL_AND_EQUAL and LOGICAL_OR_EQUAL) are partially supported in a few parts of the codebase but not at the grammar level. Does anyone remember any previous discussion about those operators?

Thanks, Paul.
Reply | Threaded
Open this post in threaded view
|

Re: Compound assignment for logic operators

Jochen Theodorou


Am 10.04.2018 um 09:00 schrieb Paul King:
>
> Hi Everyone,
>
> I noticed that the '&&=' and '||=' operators (LOGICAL_AND_EQUAL and
> LOGICAL_OR_EQUAL) are partially supported in a few parts of the codebase
> but not at the grammar level. Does anyone remember any previous
> discussion about those operators?

I don't really remember... did we maybe add it for groovypp?

bye Jochen
Reply | Threaded
Open this post in threaded view
|

Re: Compound assignment for logic operators

paulk_asert
It seems older than that. I guess we decided to follow java and C rather than Ruby.
I suspect we wouldn't want to make an override-able operator for logical and/or but I see no harm in having the short-hand itself.
Anyway, we can look at it if there is sufficient interest.

Cheers, Paul.

On Wed, Apr 11, 2018 at 2:58 AM, Jochen Theodorou <[hidden email]> wrote:


Am 10.04.2018 um 09:00 schrieb Paul King:

Hi Everyone,

I noticed that the '&&=' and '||=' operators (LOGICAL_AND_EQUAL and LOGICAL_OR_EQUAL) are partially supported in a few parts of the codebase but not at the grammar level. Does anyone remember any previous discussion about those operators?

I don't really remember... did we maybe add it for groovypp?

bye Jochen

MG
Reply | Threaded
Open this post in threaded view
|

Re: Compound assignment for logic operators

MG
Hi Paul,

do you have a use case for these operators in mind ? I guess some sort of "an error has occurred" boolean flag aggregation could profit from that:

boolean errorQ = false

errorQ ||= foo0(...)
errorQ ||= foo1(...)
errorQ ||= foo2(...)
...

if(errorQ) {
  throw new Exception("some error occurred.. ")
}

Cheers,
mg


-------- Ursprüngliche Nachricht --------
Von: Paul King <[hidden email]>
Datum: 11.04.18 11:47 (GMT+01:00)
Betreff: Re: Compound assignment for logic operators

It seems older than that. I guess we decided to follow java and C rather than Ruby.
I suspect we wouldn't want to make an override-able operator for logical and/or but I see no harm in having the short-hand itself.
Anyway, we can look at it if there is sufficient interest.

Cheers, Paul.

On Wed, Apr 11, 2018 at 2:58 AM, Jochen Theodorou <[hidden email]> wrote:


Am 10.04.2018 um 09:00 schrieb Paul King:

Hi Everyone,

I noticed that the '&&=' and '||=' operators (LOGICAL_AND_EQUAL and LOGICAL_OR_EQUAL) are partially supported in a few parts of the codebase but not at the grammar level. Does anyone remember any previous discussion about those operators?

I don't really remember... did we maybe add it for groovypp?

bye Jochen

Reply | Threaded
Open this post in threaded view
|

Re: Compound assignment for logic operators

Jochen Theodorou
In reply to this post by paulk_asert


Am 11.04.2018 um 12:44 schrieb mg:
> Hi Paul,
>
> do you have a use case for these operators in mind ? I guess some sort
> of "an error has occurred" boolean flag aggregation could profit from that:

In Java I use that all the time (sometimes to the dismay of my
colleagues), so far I had no need for this in Groovy.. strange actually.

bye Jochen
MG
Reply | Threaded
Open this post in threaded view
|

Re: Compound assignment for logic operators

MG
Wait - since when does Java have logical or and and assignment operators... ?-)

-------- Ursprüngliche Nachricht --------
Von: Jochen Theodorou <[hidden email]>
Datum: 11.04.18 12:58 (GMT+01:00)
Betreff: Re: Compound assignment for logic operators



Am 11.04.2018 um 12:44 schrieb mg:
> Hi Paul,
>
> do you have a use case for these operators in mind ? I guess some sort
> of "an error has occurred" boolean flag aggregation could profit from that:

In Java I use that all the time (sometimes to the dismay of my
colleagues), so far I had no need for this in Groovy.. strange actually.

bye Jochen
Reply | Threaded
Open this post in threaded view
|

Re: Compound assignment for logic operators

Jochen Theodorou
In reply to this post by paulk_asert


Am 11.04.2018 um 13:56 schrieb mg:
> Wait - since when does Java have logical or and and assignment
> operators... ?-)

it does not? ups... yes... |= and not ||=

Strange... I thought I used it before in Java or Groovy... I had a very
specific code in mind for that actually...
MG
Reply | Threaded
Open this post in threaded view
|

Re: Compound assignment for logic operators

MG
Maybe ||= was active in Groovy at some point ?
Or you used |= and Groovy truth made it work ?
||-)

-------- Ursprüngliche Nachricht --------
Von: Jochen Theodorou <[hidden email]>
Datum: 11.04.18 14:37 (GMT+01:00)
Betreff: Re: Compound assignment for logic operators



Am 11.04.2018 um 13:56 schrieb mg:
> Wait - since when does Java have logical or and and assignment
> operators... ?-)

it does not? ups... yes... |= and not ||=

Strange... I thought I used it before in Java or Groovy... I had a very
specific code in mind for that actually...
MG
Reply | Threaded
Open this post in threaded view
|

Re: Compound assignment for logic operators

MG
In reply to this post by Jochen Theodorou
Since Java using the operator for something else in the future seems unlikely, and confusing it with the bitwise variety can already happen for the non-assignment version, I feel adding/activating &&= and ||= would put another arrow in the Groovy quiver...

-------- Ursprüngliche Nachricht --------
Von: Jochen Theodorou <[hidden email]>
Datum: 11.04.18 14:37 (GMT+01:00)
Betreff: Re: Compound assignment for logic operators



Am 11.04.2018 um 13:56 schrieb mg:
> Wait - since when does Java have logical or and and assignment
> operators... ?-)

it does not? ups... yes... |= and not ||=

Strange... I thought I used it before in Java or Groovy... I had a very
specific code in mind for that actually...