Negative relational operators for Groovy 3

classic Classic list List threaded Threaded
40 messages Options
1234
Reply | Threaded
Open this post in threaded view
|

Negative relational operators for Groovy 3

Daniel Sun
Hi all,

      The new parser(Parrot) supports negative relational operators now, which is proposed by Guillaume Laforge :)

      Here are some example codes(https://github.com/danielsun1106/groovy-parser/blob/negativeRelationalOperators/src/test/resources/core/NegativeRelationalOperators_01x.groovy):

assert 'a' instanceof String
assert 'a' !instanceof Integer
assert 1 <= 2
assert 2 !<= 1
assert 2 >= 1
assert 1 !>= 2
assert 1 < 2
assert 2 !< 1
assert 2 > 1
assert 1 !> 2
assert 1 in [1, 2]
assert 3 !in [1, 2]

      The static compilation example codes can be found at https://github.com/danielsun1106/groovy-parser/blob/negativeRelationalOperators/src/test/resources/core/NegativeRelationalOperators_02x.groovy

       Any thoughts?

Cheers,
Daniel.Sun
Reply | Threaded
Open this post in threaded view
|

Re: Negative relational operators for Groovy 3

Jochen Theodorou


On 18.11.2016 13:45, Daniel Sun wrote:

> Hi all,
>
>       The new parser(Parrot) supports negative relational operators now,
> which is proposed by Guillaume Laforge :)
>
>       Here are some example
> codes(https://github.com/danielsun1106/groovy-parser/blob/negativeRelationalOperators/src/test/resources/core/NegativeRelationalOperators_01x.groovy):
>
> assert 'a' instanceof String
> assert 'a' !instanceof Integer
> assert 1 <= 2
> assert 2 !<= 1
> assert 2 >= 1
> assert 1 !>= 2
> assert 1 < 2
> assert 2 !< 1
> assert 2 > 1
> assert 1 !> 2
> assert 1 in [1, 2]
> assert 3 !in [1, 2]

I think !instanceof and !in are ok. The others... not sure here. Right
now a<b uses the same method as a>=b, which means !< is >=. And in this
case I actually prefer >=.

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

Re: Negative relational operators for Groovy 3

Jochen Theodorou
In reply to this post by Daniel Sun


On 18.11.2016 13:45, Daniel Sun wrote:

> Hi all,
>
>       The new parser(Parrot) supports negative relational operators now,
> which is proposed by Guillaume Laforge :)
>
>       Here are some example
> codes(https://github.com/danielsun1106/groovy-parser/blob/negativeRelationalOperators/src/test/resources/core/NegativeRelationalOperators_01x.groovy):
>
> assert 'a' instanceof String
> assert 'a' !instanceof Integer
> assert 1 <= 2
> assert 2 !<= 1
> assert 2 >= 1
> assert 1 !>= 2
> assert 1 < 2
> assert 2 !< 1
> assert 2 > 1
> assert 1 !> 2
> assert 1 in [1, 2]
> assert 3 !in [1, 2]

oh... and one question... is "! in" the same as "!in"?

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

Re: Negative relational operators for Groovy 3

Daniel Sun
Hi Jochen,

> oh... and one question... is "! in" the same as "!in"?
    Yeah, the negative relational operators are combined operators, which will be transformed to normal NotExpression :)

Cheers,
Daniel.Sun
Reply | Threaded
Open this post in threaded view
|

Re: Negative relational operators for Groovy 3

Guillaume Laforge
Administrator
In reply to this post by Jochen Theodorou

On Fri, Nov 18, 2016 at 1:58 PM, Jochen Theodorou <[hidden email]> wrote:


On 18.11.2016 13:45, Daniel Sun wrote:
Hi all,

      The new parser(Parrot) supports negative relational operators now,
which is proposed by Guillaume Laforge :)

      Here are some example
codes(https://github.com/danielsun1106/groovy-parser/blob/negativeRelationalOperators/src/test/resources/core/NegativeRelationalOperators_01x.groovy):

assert 'a' instanceof String
assert 'a' !instanceof Integer
assert 1 <= 2
assert 2 !<= 1
assert 2 >= 1
assert 1 !>= 2
assert 1 < 2
assert 2 !< 1
assert 2 > 1
assert 1 !> 2
assert 1 in [1, 2]
assert 3 !in [1, 2]

I think !instanceof and !in are ok. The others... not sure here. Right now a<b uses the same method as a>=b, which means !< is >=. And in this case I actually prefer >=.

For instanceof and in, that's nice, but I think it's too cryptic for the other ones, which do exist in a different form, as currently !< is just >=, as Jochen says. 
 
--
Guillaume Laforge
Apache Groovy committer & PMC Vice-President
Developer Advocate @ Google Cloud Platform

Reply | Threaded
Open this post in threaded view
|

Re: Negative relational operators for Groovy 3

Guillaume Laforge
Administrator

On Fri, Nov 18, 2016 at 2:05 PM, Guillaume Laforge <[hidden email]> wrote:

On Fri, Nov 18, 2016 at 1:58 PM, Jochen Theodorou <[hidden email]> wrote:


On 18.11.2016 13:45, Daniel Sun wrote:
Hi all,

      The new parser(Parrot) supports negative relational operators now,
which is proposed by Guillaume Laforge :)

      Here are some example
codes(https://github.com/danielsun1106/groovy-parser/blob/negativeRelationalOperators/src/test/resources/core/NegativeRelationalOperators_01x.groovy):

assert 'a' instanceof String
assert 'a' !instanceof Integer
assert 1 <= 2
assert 2 !<= 1
assert 2 >= 1
assert 1 !>= 2
assert 1 < 2
assert 2 !< 1
assert 2 > 1
assert 1 !> 2
assert 1 in [1, 2]
assert 3 !in [1, 2]

I think !instanceof and !in are ok. The others... not sure here. Right now a<b uses the same method as a>=b, which means !< is >=. And in this case I actually prefer >=.

For instanceof and in, that's nice, but I think it's too cryptic for the other ones, which do exist in a different form, as currently !< is just >=, as Jochen says. 

In terms of "groovy style", I think I'd prefer to have the ! sticking to in and instanceof. 
It might also be less confusing to parse, should we some day add something like a factorial operator, or some other use for the ! 


--
Guillaume Laforge
Apache Groovy committer & PMC Vice-President
Developer Advocate @ Google Cloud Platform

Reply | Threaded
Open this post in threaded view
|

Re: Negative relational operators for Groovy 3

Daniel Sun
In reply to this post by Jochen Theodorou
Hi Jochen,

>  I think !instanceof and !in are ok. The others... not sure here. Right
>  now a=b, which means !< is >=. And in this
>  case I actually prefer >=.

     Sometimes we write code like "!(a > b)", now we can write "a !> b" instead, which is much close to our mind :)

Cheers,
Daniel.Sun

Reply | Threaded
Open this post in threaded view
|

Re: Negative relational operators for Groovy 3

Cédric Champeau
I agree with Jochen and Guillaume: +1 to !instanceof and !in, but I don't like the other variants.

2016-11-18 14:11 GMT+01:00 Daniel Sun <[hidden email]>:
Hi Jochen,

>  I think !instanceof and !in are ok. The others... not sure here. Right
>  now a*=b, which means !< is >=. And in this
>  case I actually prefer >=.

     Sometimes we write code like "!(a > b)", now we can write "a !> b"
instead, which is much close to our mind :)

Cheers,
Daniel.Sun





--
View this message in context: http://groovy.329449.n5.nabble.com/Negative-relational-operators-for-Groovy-3-tp5736809p5736816.html
Sent from the Groovy Dev mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: Negative relational operators for Groovy 3

Daniel Sun
In reply to this post by Guillaume Laforge
OK. As most of us just like !in and !instanceof and prefer the sticky style, I will modify them later. Thanks for your review ;)

Cheers,
Daniel.Sun




在 "Guillaume Laforge [via Groovy]" <ml-node+[hidden email]>,2016年11月18日 下午9:07写道:


On Fri, Nov 18, 2016 at 2:05 PM, Guillaume Laforge <[hidden email]> wrote:

On Fri, Nov 18, 2016 at 1:58 PM, Jochen Theodorou <[hidden email]> wrote:


On 18.11.2016 13:45, Daniel Sun wrote:
Hi all,

      The new parser(Parrot) supports negative relational operators now,
which is proposed by Guillaume Laforge :)

      Here are some example
codes(https://github.com/danielsun1106/groovy-parser/blob/negativeRelationalOperators/src/test/resources/core/NegativeRelationalOperators_01x.groovy):

assert 'a' instanceof String
assert 'a' !instanceof Integer
assert 1 <= 2
assert 2 !<= 1
assert 2 >= 1
assert 1 !>= 2
assert 1 < 2
assert 2 !< 1
assert 2 > 1
assert 1 !> 2
assert 1 in [1, 2]
assert 3 !in [1, 2]

I think !instanceof and !in are ok. The others... not sure here. Right now a<b uses the same method as a>=b, which means !< is >=. And in this case I actually prefer >=.

For instanceof and in, that's nice, but I think it's too cryptic for the other ones, which do exist in a different form, as currently !< is just >=, as Jochen says. 

In terms of "groovy style", I think I'd prefer to have the ! sticking to in and instanceof. 
It might also be less confusing to parse, should we some day add something like a factorial operator, or some other use for the ! 


--
Guillaume Laforge
Apache Groovy committer & PMC Vice-President
Developer Advocate @ Google Cloud Platform




If you reply to this email, your message will be added to the discussion below:
http://groovy.329449.n5.nabble.com/Negative-relational-operators-for-Groovy-3-tp5736809p5736815.html
To unsubscribe from Negative relational operators for Groovy 3, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: Negative relational operators for Groovy 3

Daniel Sun
In reply to this post by Cédric Champeau
OK. I see :)



在 Cédric Champeau [via Groovy] <ml-node+[hidden email]>,2016年11月18日 下午9:18写道:

I agree with Jochen and Guillaume: +1 to !instanceof and !in, but I don't like the other variants.

2016-11-18 14:11 GMT+01:00 Daniel Sun <[hidden email]>:
Hi Jochen,

>  I think !instanceof and !in are ok. The others... not sure here. Right
>  now a*=b, which means !< is >=. And in this
>  case I actually prefer >=.

     Sometimes we write code like "!(a > b)", now we can write "a !> b"
instead, which is much close to our mind :)

Cheers,
Daniel.Sun





--
View this message in context: http://groovy.329449.n5.nabble.com/Negative-relational-operators-for-Groovy-3-tp5736809p5736816.html
Sent from the Groovy Dev mailing list archive at Nabble.com.




If you reply to this email, your message will be added to the discussion below:
http://groovy.329449.n5.nabble.com/Negative-relational-operators-for-Groovy-3-tp5736809p5736817.html
To unsubscribe from Negative relational operators for Groovy 3, click here.
NAML
1234