Operator Overloading

Monkey Forums/Monkey Programming/Operator Overloading

Sammy(Posted 2012) [#1]
Any way to do this?


maltic(Posted 2012) [#2]
I don't know of any way, and I don't believe there is one.

I really wish there was.


AdamRedwoods(Posted 2012) [#3]
No. I can see when it's useful, but I've seen it used where it hides/confuses functionality. I try to stay away from it.

Java and javascript do not allow operator overloading, so it shouldn't be in monkey either.
Use Methods for now (a.Add(b))


Gerry Quinn(Posted 2012) [#4]
It makes code nicer when you are dealing with mathematical objects that have natural interpretations of operators. I would use it for things like Point and Size classes if it was there, but I can live happily enough without it.

I don't see why Monkey should follow the rules of Java and Javascript. But I do see an argument against operator overloading which is that Monkey, despite being a sophisticated language, is also beginner-friendly, with a lot of syntax coming from Basic - and I'm not sure operator overloading fits well into that.


Nicholas Peanut(Posted 2012) [#5]
"I don't see why Monkey should follow the rules of Java and Javascript"
lowest common denominator, since monkey is translated to many


ziggy(Posted 2012) [#6]
lowest common denominator, since monkey is translated to many
That would leave lots and lots of features we already have out, such as reflection, overloading, hardtyped nature, generics...


maltic(Posted 2012) [#7]
lowest common denominator, since monkey is translated to many


Operator overloading is determined at compile time, not run time. Hence its irrelevant if the target language supports it. Take C++ for example, its target compilation language definitely doesn't support generics, variable types (outside of different length words), objects, functions, operator overloading... etc. As such I personally would like to see a few of the more interesting features in Monkey. Though as Gerry said, one of the important constraints is to keep Monkey beginner friendly.


Sammy(Posted 2012) [#8]
Thanks for the replies, well I would have liked it for various reasons. I was surprised it is missing TBH but oh well, maybe I can make it a request for a future version then.


Nicholas Peanut(Posted 2012) [#9]
sorry for my spread of misinfo then, glad I learned something in the process