orc-lang / orc

Orc programming language implementation
https://orc.csres.utexas.edu/
BSD 3-Clause "New" or "Revised" License
40 stars 3 forks source link

Add support for operator methods #173

Open arthurp opened 7 years ago

arthurp commented 7 years ago

This would allow Orc to do away with special operator support for some values. In addition, it would eliminate the need for the messy numeric operators with all the type dispatching.

Initially we could just support the existing operators (so as not to have to worry about how to parse things) and support those as method names. However, eventually it would be nice to support arbitrary names which are a sequence of symbols. Unlike Scala we do not plan to allow alpha numeric names to be used in infix notation or allow symbolic methods to be used with a dot and parens.

arthurp commented 7 years ago

This would replace the existing support for the functions (+), etc. They probably cannot coexist because they cannot be disambiguated at parse time. This implies that this change would force an update to the numerics tower. But we already wanted to do that: #18

arthurp commented 6 years ago

I think the short term solution to this is actually to just replace all the operator functions in the standard library defs which call a method on their left argument. For instance:

def (+)(a, b) = a.(+)(b)

This will allow all the currently existing operators to work with any class that implements them.

To make this work we would need to add special handling so that Number and other important numeric types appear to have the various methods: (+), (*), etc. The same would need to be done for lists (for (:)) and maybe a few other types. However, if we setup simple framework for doing this kind of patching it should be easy to do.