PS' implementation of &optional function arguments breaks because of JS's weird short-circuiting. For example,
(ps (defun blah (&optional (x 0)) (return x))) => "function blah(x) { x = undefined === x && 0 || x; return x; };"
With this implementation, blah() is undefined when it should return 0.
A patch is below.
Daniel
hunk ./src/special-forms.lisp 268 - `(setf ,place (or (and (=== undefined ,place) ,value) - ,place))) + `(setf ,place (if (=== ,place undefined) ,value ,place)))
Daniel Gackle wrote:
PS' implementation of &optional function arguments breaks because of JS's weird short-circuiting. For example,
(ps (defun blah (&optional (x 0)) (return x))) => "function blah(x) { x = undefined === x && 0 || x; return x; };"
With this implementation, blah() is undefined when it should return 0.
You may have noticed this, but for passer-bys I'll note that the reason for this is actually a bit nuanced. You'll notice this only occurs when your default value for x is zero. Zero is false in JS, so 0 || x always returns x even if x is undefined.
Thanks for the report. I've pushed a fix for this that should be more robust to this type of thing.
Cheers,
-- Travis
parenscript-devel@common-lisp.net