Re:Wren is a small, fast, class-based concurrent scripting l...
by munificent on Monday August 29, 2022 @12:08PM
(#32639872)
> I don't know why you have operator overloading at all.
Wren doesn't have "operator overloading". There is no separate feature in addition to the normal operator support that also lets you overload them. Wren just uses single dispatch for infix operators. Even the "built in" operator behavior like addition on numbers is simply pre-defined methods on the Number class. Like Smalltalk (which Wren is heavily inspired by), everything is just a method call and there is little "special" behavior for primitives.
Re:Wren is a small, fast, class-based concurrent scripting l...
by randomswede on Tuesday August 30, 2022 @03:17AM
(#32647535)
So if I understand this correctly, "a + b" is syntactic sugar for "a.+(b)" (modulo the exact name of the method)?
Re:Wren is a small, fast, class-based concurrent scripting l...
by munificent on Tuesday August 30, 2022 @12:32PM
(#32652276)
Yes, exactly. Basically everything is method calls.
Yes, static typing would be a huge change, but I think you're greatly exaggerating the complexity of multimethods for (only) binary operators. You don't want to do it, which is fine. It's your language, and you don't owe anyone anything, but be honest about your rationale.
You've already got a failure path to report errors when the types don't work, so falling back to a single global table of "first_type x second_type => function" is not more "huge" than anything else. You don't need scoping for operators like this, so it's literally one table. You can see the code in your head as you read this. I'm sure you could fill in the details or imagine some other simple implementation if you wanted to.