3 ms·
I feel like the ocaml solution would fit zigs usecase well. In ocaml you can redefine operators... but only in the context of another module. So if I re-defin
by LAC-Tech 2y ago
I feel like the ocaml solution would fit zigs usecase well.
In ocaml you can redefine operators... but only in the context of another module.
So if I re-define + in some module Vec3, I can do:
Vec3.(a + b + c + d)
Or even:
let open Vec3 in
a + b + c + d
So there you go, no "where did the + operator come from?" questions when reading the source, and still much nicer than:
a.add(b).add(c).add(d)
I doubt zig will change though. The language is starting to crystallize and anything that solved this challenge would be massive.
- flohofwoe 2y agoFor something as simple as a vec3 type, Zig has a @Vector 'meta-type', it's quite bare bones though: https://ziglang.org/documentation/master/#Vector https://ziglang.org/documentation/master/#Vector