[parenscript-devel] Bug: &optional arguments stay undefined when they shouldn't

Travis Cross tc at travislists.com
Sat Nov 15 05:47:02 UTC 2008


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




More information about the parenscript-devel mailing list