[parenscript-devel] wrong operator priority?

Alex Mizrahi alex.mizrahi at gmail.com
Thu Sep 25 12:05:16 UTC 2008


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? 




More information about the parenscript-devel mailing list