[parenscript-devel] Evaluation of default values for keyword args

Daniel Gackle danielgackle at gmail.com
Tue Dec 7 05:10:01 UTC 2010


I'm glad to see the tighter code being generated for keyword
arguments, but I'm afraid there's a problem. If a default value is
provided, it is now being evaluated whether it's needed or not:

(defun blah (&key (param (long-running-computation)))
  (foo param))

=>

function blah() {
    var param = longRunningComputation();
    var _js10 = arguments.length;
    // ...
    return foo(param);
};

Compare this to:

(defun blah (&optional (param (long-running-computation)))
  (foo param))

=>

function blah(param) {
    if (param === undefined) {
        param = longRunningComputation();
    };
    return foo(param);
};

I think the above keyword behavior is incorrect and the optionals have
it right. Yet I like the fact that all the sludge of the "if
variable remains undefined after sucking out the optional arguments
then set it to null" sort has been removed.

Is there a compromise? For example, could we do it the simpler way
where the default value is a constant?

Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/parenscript-devel/attachments/20101206/20290924/attachment.html>


More information about the parenscript-devel mailing list