Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


I thought that was only true in languages with lazy evaluation? Otherwise how do you implement short-circuiting operators?


Yes, 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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: