In fact, the procedure-based version my-or
is different from the built-in or
. To prove it, just try this:
(or 1 (/ 1 0))
=> 1
(my-or 1 (/ 1 0))
=> /: division by zero
Explanation:
- The built-in
or
is a special form, meaning: the evaluation rules that normally apply for procedures are different foror
(and by the way, the same is true forand
) or
short-circuits the evaluation of its parameters: the value of the first parameter that returns non-false is returned as the result, and the rest of the parameters will not be evaluated!my-or
performs a normal function call, and all its parameters will be evaluated before passing them tomy-or
's body- The example above shows that clearly:
or
doesn't evaluate the division by zero, it returns as soon as it finds the first non-false value, whereasmy-or
evaluates both parameters before proceeding, and it fails because it encounters a division by zero