3 ms·
They are all just functions. There is really no distinction between an operator and a function in programming languages. And by using currying you could even do
by jcarrano 2y ago
They are all just functions. There is really no distinction between an operator and a function in programming languages. And by using currying you could even do with just unary operators.
- EE84M3i 2y agoI thought that was only true in languages with lazy evaluation? Otherwise how do you implement short-circuiting operators?
- jcarrano 2y agoYes, but I meant it in the most abstract, conceptual sense. There is no easy way to replace short-circuit operators in an eager-evaluation language but it can still be done. E.g. "(a() || b())" could be replaced by "or(a, b)", which is quite challenging to do in C, though possible in C++, Python, and other languages which have closures: def or(a, b): r = a() if not r: r = b() return r