Closed domdefelice closed 13 years ago
Another case where we should be following traditional lisp semantics. Just in case: The same goes for IF, AND, COND, etc. so if we have those and they don't already to this, make sure they do (though I believe IF already follows this).
Also, check out this xkcd for some real insight: http://m.xkcd.com/870/.
The issue here is that PHP doesn't seem to natively support this behavior for its logical operators. I guess the solution would be to convert them to ternary statements but I'm not sure if there'd be a performance penalty. Ideally there shouldn't be, but the PHP internals can be rather messy.
Doesn't the IF
implementation just assign a variable? Either way, modulo multiple evaluation (which would be solved with a LET
), just translate:
(or a b)
to:
(if a a b)
Yep, I just wasn't sure if PHP would add some extra overhead to if statements. Some quick benchmarks show that if statements were as fast as ternary statements. I really need to stop irrationally fearing PHP internals :)
Implementing this now.
(or FALSE "string") should return "string" but returns 1. It always returns 0 or 1, but should return 0 (FALSE) or the element that was not FALSE, so to make possible to use something like (print (or variable "default string")).