I pushed a patch to assign the init form to a keyword var only when the var is undefined, as described below.<div><br></div><div>(Also a couple of other minor things: to use a gensym rather than hard-coded E for error var in IGNORE-ERRORS and to generate correct code for ^ in variable names.  A naming convention I've become enamored of lately is to have a variable X^ to mean "the preceding version of X" à la git.)</div>

<div><br></div><div><br><div class="gmail_quote">On Tue, Jan 11, 2011 at 2:59 PM, Daniel Gackle <span dir="ltr"><<a href="mailto:danielgackle@gmail.com">danielgackle@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div>I'm still encountering a bug with this issue: The JS incorrectly assigns the default value when the caller supplies a value for PARAM that is NIL (or 0, or false).</div><div><br></div><div>I suppose the immediate fix is to only assign the default value when PARAM is undefined?</div>


<div><br></div><div>I'm a little uncomfortable relying on the serious weirdness of JS surrounding global/local vars in order to implement this feature, but if there's no other alternative that is both correct and equally fast as this one, then I guess that trumps other concerns.</div>

<div><div></div><div class="h5">
<div> </div><div><br></div><br><div class="gmail_quote">On Thu, Dec 9, 2010 at 11:41 PM, Vladimir Sedach <span dir="ltr"><<a href="mailto:vsedach@gmail.com" target="_blank">vsedach@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


That is indeed a bug. Here's the solution I came up with:<br>
<div><br>
(defun blah (&key (param (long-running-computation)))<br>
  (foo param))<br>
<br>
=><br>
<br>
function blah() {<br>
</div>    var _js4 = arguments.length;<br>
    for (var n3 = 0; n3 < _js4; n3 += 2) {<br>
        switch (arguments[n3]) {<br>
        case 'param':<br>
            param = arguments[n3 + 1];<br>
        };<br>
    };<br>
    var param = param ? param : longRunningComputation();<br>
    return foo(param);<br>
};<br>
<br>
Believe it or not, this actually does the right thing when param has<br>
previously been declared as a global variable.<br>
<br>
Vladimir<br>
<br>
2010/12/7 Daniel Gackle <<a href="mailto:danielgackle@gmail.com" target="_blank">danielgackle@gmail.com</a>>:<br>
<div><div></div><div>> I'm glad to see the tighter code being generated for keyword<br>
> arguments, but I'm afraid there's a problem. If a default value is<br>
> provided, it is now being evaluated whether it's needed or not:<br>
> (defun blah (&key (param (long-running-computation)))<br>
>   (foo param))<br>
> =><br>
> function blah() {<br>
>     var param = longRunningComputation();<br>
>     var _js10 = arguments.length;<br>
>     // ...<br>
>     return foo(param);<br>
> };<br>
> Compare this to:<br>
> (defun blah (&optional (param (long-running-computation)))<br>
>   (foo param))<br>
> =><br>
> function blah(param) {<br>
>     if (param === undefined) {<br>
>         param = longRunningComputation();<br>
>     };<br>
>     return foo(param);<br>
> };<br>
> I think the above keyword behavior is incorrect and the optionals have<br>
> it right. Yet I like the fact that all the sludge of the "if<br>
> variable remains undefined after sucking out the optional arguments<br>
> then set it to null" sort has been removed.<br>
> Is there a compromise? For example, could we do it the simpler way<br>
> where the default value is a constant?<br>
> Daniel<br>
</div></div>> _______________________________________________<br>
> parenscript-devel mailing list<br>
> <a href="mailto:parenscript-devel@common-lisp.net" target="_blank">parenscript-devel@common-lisp.net</a><br>
> <a href="http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel" target="_blank">http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel</a><br>
><br>
><br>
<br>
_______________________________________________<br>
parenscript-devel mailing list<br>
<a href="mailto:parenscript-devel@common-lisp.net" target="_blank">parenscript-devel@common-lisp.net</a><br>
<a href="http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel" target="_blank">http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel</a><br>
</blockquote></div><br>
</div></div></blockquote></div><br></div>