[parenscript-devel] wrong operator priority?
this piece of parenscript: (defun my-element-by-id (cache id) (return (or (slot-value cache id) (setf (slot-value cache id) (document.get-element-by-id id))))) gets transformed to: function myElementById(cache, id) { return cache[id] || cache[id] = document.getElementById(id); }; which i believe is wrong -- browsers interpret it (according to JS operator priority rules, i guess) as return (cache[id] || cache[id]) = document.getElementById(id); and complain about wrong assignment to non-lvalue. while with correctly set parentheses it works fine: function myElementById(cache, id) { return cache[id] || (cache[id] = document.getElementById(id)); }; so, i guess, parenscript should detect this operator priority problem and insert parentheses correctly?
Alex Mizrahi wrote:
this piece of parenscript:
(defun my-element-by-id (cache id) (return (or (slot-value cache id) (setf (slot-value cache id) (document.get-element-by-id id)))))
now returns: function myElementById(cache, id) { return cache[id] || (cache[id] = document.getElementById(id)); }; Thanks for the report! Cheers, -- Travis
participants (2)
-
Alex Mizrahi
-
Travis Cross