Ok, I just realized that I completely misread your original post. I thought you were proposing the removal of defaulting to null rather than leaving the value undefined.<div><br></div><div>Have you done any profiling to see if there is a reasonable difference between</div>
<div><br></div><div><div>"function foo() {</div><div> var a;</div><div> // ... pick out and assign keyword args ...</div><div> if (a === undefined) {</div><div> a = null;</div><div> };</div><div> return bar(a);</div>
<div>};"</div><div><br></div><div>and </div><div><br></div><div><div>"function foo() {</div><div> var a = null;</div><div> // ... pick out and assign keyword args ...</div><div> return bar(a);</div><div>
};"</div></div><div><br></div>?</div><div><br></div><div>I just ran this very naive test in Chromium:</div><div><br></div><div><font class="Apple-style-span" face="'courier new', monospace">var then = +new Date;</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">var i = 20000;</font></div><div><font class="Apple-style-span" face="'courier new', monospace">while (i--) {</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> (function () {</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> var a;</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> if (a === undefined) a = null;</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> }())</font></div><div><font class="Apple-style-span" face="'courier new', monospace">};</font></div><div><font class="Apple-style-span" face="'courier new', monospace">console.log(+new Date - then);</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br><font class="Apple-style-span" face="arial">Which logs 70 ms.</font></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
var then = +new Date;</font></div><div><font class="Apple-style-span" face="'courier new', monospace">var i = 20000;</font></div><div><font class="Apple-style-span" face="'courier new', monospace">while (i--) {</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> (function () {</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> var a = null;</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> }())</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">};</font></div><div><font class="Apple-style-span" face="'courier new', monospace">console.log(+new Date - then);<br><br></font><div><br>
</div><div>This one logs 71 ms.</div><div><br></div><div>This has to have come up before, but why not just use an object as the only parameter and use it's keys as the keyword arguments? I just ran the same test for that, and when the keyword was missing I got 82 ms, but when it was available, I got 56.</div>
<div><br></div><div>I think using objects would make the generated code much more readable, which trumps speed in this case IMO given that the difference is so small and the high number of iterations being performed.</div>
<div><br></div>_Nick_<br><br>
<br><br><div class="gmail_quote">On Thu, Aug 5, 2010 at 1:24 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;">
Good point. I kept the null assignment for consistency with how PS does &optional<div>arguments. But this begs the question: why do we care about &optional</div><div>and &key arguments being set to null, as opposed to just leaving them undefined?</div>
<div>I'm trying to remember the reason... anybody?</div><div><br></div><div>Our experience has been that PS code works best if one treats null and undefined </div><div>as interchangeable. But that may be an artifact of running some of the same code</div>
<div>in CL as well, where there is no such distinction.</div><div><div></div><div class="h5"><div><br></div><div><br><div class="gmail_quote">On Thu, Aug 5, 2010 at 1:51 PM, Nick Fitzgerald <span dir="ltr"><<a href="mailto:fitzgen@gmail.com" target="_blank">fitzgen@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">+1 from me but that doesn't mean too much.<div><br></div><div>No need to explicitly set them as `null`, because JS already has (the more semantic in this case) `undefined`.<br clear="all">
<br>_Nick_<br><br>
<br><br><div class="gmail_quote"><div><div></div><div>On Wed, Aug 4, 2010 at 12:30 PM, Daniel Gackle <span dir="ltr"><<a href="mailto:danielgackle@gmail.com" target="_blank">danielgackle@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div>
The code that's generated for a keyword argument goes like this:<div><div><br></div><div><div>(ps (defun foo (&key a) (bar a))) => </div><div><br></div><div>(abbreviated for clarity):</div><div><br></div><div>
"function foo() {</div>
<div> var a;</div><div> // ... pick out and assign keyword args ...</div><div> if (a === undefined) {</div><div> a = null;</div><div> };</div><div> return bar(a);</div><div>};"</div></div></div>
<div>
<br></div><div>It seems to me that this could be made tighter as follows:</div><div><br></div><div><div>"function foo() {</div><div> var a = null;</div><div> // ... pick out and assign keyword args ...</div><div>
return bar(a);</div><div>};"</div></div><div><br></div><div>The only difference I can think of is when someone explicitly passes undefined</div><div>as a value for the argument, but that's an oxymoronic thing to do.</div>
<div><br></div><div>Can anyone think of a reason not to make this change? I like PS's keyword</div><div>arguments a lot, but the generated JS is bloated enough to make me wince.</div>
<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></blockquote></div><br></div>
<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>
<br></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
parenscript-devel mailing list<br>
<a href="mailto:parenscript-devel@common-lisp.net">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></blockquote></div><br></div>