I have found this question about the special function “or” in scheme:
Joe Hacker states loudly that there is no reason or in Scheme needs to be special — it can just be defined by the programmer, like this:
(define (or x y) (if x #t y))Is Joe right?
I can’t figure out why it shouldn’t be possible to do that.
Could some scheme-expert please explain if this works, and if no: why not?
It’s because this version of
orevaluates all of its arguments (since it’s a function), while the standard Schemeor(which is not a function but special syntax) doesn’t. Try running(or #t (exit))at the Scheme REPL and then try the same with yourorfunction.The behavior of the standard
oris sometimes called short-circuited: it evaluates only those arguments that it needs to. This is very common for the binary boolean operator (orandand) across programming languages. The fact thatorlooks like a function call is a feature of Scheme/Lisp syntax, but looks deceive.