expr icon indicating copy to clipboard operation
expr copied to clipboard

Arithmetic operator override

Open regel opened this issue 4 years ago • 3 comments

Hi.

Such a cool project, bravo!

I wrote a small test app using the '+' operator over arrays of integers and arrays of floats. Since I could not use the '+' operator, I implemented a short 'add' function to test this feature and it works.

To build this feature in expr and override the '+' (and other arithmetic operators), where would be the good place to experiment in the source code?

Experimentation stage for now. Happy to share a pull-request if something good comes out of this experiment.

Cheers.

regel avatar Dec 01 '20 10:12 regel

Did you read this? https://github.com/antonmedv/expr/blob/master/docs/Operator-Override.md

antonmedv avatar Dec 01 '20 17:12 antonmedv

ok, thanks! I totally missed this section in the documentation.

	expr.Operator("-", "Sub"), // Override `-` with function `Sub`.

If there are multiple types, all ints and floats variants, is it possible to duplicate the above call multiple times with their respective callback function?

regel avatar Dec 01 '20 19:12 regel

Didn’t got what you mean.

antonmedv avatar Dec 01 '20 19:12 antonmedv