groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel.Sun" <>
Subject Re: Custom operator for Groovy 3
Date Sun, 30 Oct 2016 16:34:57 GMT
Hi Jochen,

     I'll set aside more time on your new idea ;)


在 "Jochen Theodorou [via Groovy]" <>,2016年10月30日

On 30.10.2016 11:07, Daniel.Sun wrote:

> Hi Paolo,
>       There are some limitations when we use antlr to define grammar, so the
> backticks are used to distinguish with other operators.
>       I saw an answer from Jochen(shown as follow), so I tryied to add this
> experimental feature
>       "We always wanted the ability to define an operator through the user in
> Groovy, but so far we haven't gotten around the problems that come along
> with that."

I actually gave up on custom operators for a bit.

In Scala you have a natural mapping of "a + b" to a."+"(b). But in
Groovy that would be a(+).b. That means binary expressions and command
expressions follow different patterns. That means in a+b+c we do not
naturally get (a+b)+c, we get a(+).b(+).c. This is what makes you
require special characters to distinguish operators and command
expressions in the usage of those

And if you change precedence rules like you described... a + b + c  is
(a+b)+c while a + b "`x`" c  would become a+(b "`x`" c) instead.

But to develop the idea... how about saying that everything between dot
and an identifier is an operator? So a .x c would be a.x(c).. well that
looks obvious, but a .>? c becomes a.">?"(c). This kind of logic would
reduce the need for special characters and be in line with existing
syntax. And at the same time precedence rule would be clear. a + b .>? c
would be a+(b.">?"(c)) and a .>? b +c would become (a.">?"(b))+c

bye Jochen

If you reply to this email, your message will be added to the discussion below:
To unsubscribe from Custom operator for Groovy 3, click here<>.

View this message in context:
Sent from the Groovy Dev mailing list archive at
View raw message