[parenscript-devel] Bug in PS operator precedence
Daniel Gackle
danielgackle at gmail.com
Tue Oct 14 21:29:12 UTC 2008
I got bitten by this bug:
(ps (or x (if (= x 0) "zero" "empty")))
=> "x || x == 0 ? 'zero' : 'empty'"
This is wrong, because it evaluates to 'zero' for any value of x, instead of
just when x is 0. The correct expansion is:
x || (x == 0 ? 'zero' : 'empty')
It seems that Parenscript simply has JS operator precedence wrong for the
"if" (question-mark) operator. The following web page (which claims to be
reporting what the ECMA spec says) makes it clear that the "if" operator's
precedence is between that of "or" and the assignment operators.
http://www.codehouse.com/javascript/precedence/
So a simple fix is:
hunk ./src/printer.lisp 110
- (in js-expression-if)
+ (in)
hunk ./src/printer.lisp 118
+ (js-expression-if)
Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/parenscript-devel/attachments/20081014/343ea744/attachment.html>
More information about the parenscript-devel
mailing list