> The very concept of operator overloading is incompatible with such a guarantee.
Why would operator overloading allocate memory? The memory is already allocated(by the user) when you call with the operands.
What if I wanted to overload the + operator to concatenate strings?
There is definitely some merit in being puritanical about not having any allocations in operators.
Not operator overloading; just overloading. You can't overload ordinary-named subroutines in Zig either.
> and then you know plus (with two arguments) has a different meaning in that module.
That's not overloading, that's shadowing. Overloading is when the same name refers to multiple things depending on the type of its arguments. Erlang allows overloading based on arity, but that's something that can be understood from the call-site code.
Can you explain this a bit? Operator overloading just seems like such a strange bugbear of Zig folks to me. Maybe I've just never been bitten by it, but at least in Elixir, my main language, I've never really understood the danger.
Are operators truly so different from functions? You'd expect that any function you import could do, well, anything. Aren't operators essentially just the same thing, just with a "prelude" in the language that basically imports them by default?
In Elixir, you might have (discouraged):
and then you know to check what's defined by MyOperators, for that module. But more common, if you really wanted to overload, would be to be more specific: and then you know plus (with two arguments) has a different meaning in that module.