You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Luke Bemish (Jira)" <ji...@apache.org> on 2022/08/30 21:59:00 UTC

[jira] [Updated] (GROOVY-10735) Overloading assignment-and-arithmetic operators separately from arithmetic operators

     [ https://issues.apache.org/jira/browse/GROOVY-10735?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Luke Bemish updated GROOVY-10735:
---------------------------------
    Description: Groovy allows overloading arithmetical operators (+{+}, -, etc.); however, this overloading behavior does not allow for an ease of expression of operations which ought to mutate the original object. For instance, I might have a Matrix class that, for performance reasons, ought to be mutated at times instead of constructing a new matrix every operation. Currently, there is no way to overload the "{+}=" operator to tell Groovy that, instead of constructing a new object using my overload of "plus", it should instead use some other overload for "addition and assignment". This results in either not being able to use operator overloads, or a performance impact from the creation of new mods.  (was: Groovy allows overloading arithmetical operators (+, *, -, etc.); however, this overloading behavior does not allow for an ease of expression of operations which ought to mutate the original object. For instance, I might have a Matrix class that, for performance reasons, ought to be mutated at times instead of constructing a new matrix every operation. Currently, there is no way to overload the "+=" operator to tell Groovy that, instead of constructing a new object using my overload of "plus", it should instead use some other overload for "addition and assignment". This results in either not being able to use operator overloads, or a performance impact from the creation of new mods.)

> Overloading assignment-and-arithmetic operators separately from arithmetic operators
> ------------------------------------------------------------------------------------
>
>                 Key: GROOVY-10735
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10735
>             Project: Groovy
>          Issue Type: Improvement
>          Components: Compiler
>    Affects Versions: 4.0.4
>            Reporter: Luke Bemish
>            Priority: Minor
>
> Groovy allows overloading arithmetical operators (+{+}, -, etc.); however, this overloading behavior does not allow for an ease of expression of operations which ought to mutate the original object. For instance, I might have a Matrix class that, for performance reasons, ought to be mutated at times instead of constructing a new matrix every operation. Currently, there is no way to overload the "{+}=" operator to tell Groovy that, instead of constructing a new object using my overload of "plus", it should instead use some other overload for "addition and assignment". This results in either not being able to use operator overloads, or a performance impact from the creation of new mods.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)