[parenscript-devel] Bug: let within an outer let's init-form

Vladimir Sedach vsedach at gmail.com
Thu Nov 29 03:31:14 UTC 2012


Believe it or not, that's actually valid JavaScript code:

PS> (ps (let ((x (let ((y 12))
                   (+ 1 2)
                   y)))
      (1+ x)))
"(function () {
    var y;
    var x = (y = 12, (1 + 2, y));
    return x + 1;
})();"
PS> (cl-js:run-js *)
13

In your example, a() and b() were expressions, so the inner let
generated a sequence of expressions by using the comma operator. If
for example you replace b() by a statement:

PS> (ps (let ((x (let ((y 12))
                (dolist (x '(1 2 3))
                  (* x x))
                y)))
       (1+ x)))
"(function () {
    var y;
    var x4 = (y = 12, ((function () {
        for (var x = null, _js_arrvar6 = [1, 2, 3], _js_idx5 = 0;
_js_idx5 < _js_arrvar6.length; _js_idx5 += 1) {
            x = _js_arrvar6[_js_idx5];
            x * x;
        };
    })(), y));
    return x4 + 1;
})();"
PS> (cl-js:run-js *)
13

This is ugly, and I would love examples of how to generate better code
for nested LETs.

Happy hacking,
Vladimir


On Wed, Oct 24, 2012 at 5:50 AM, Andy Peterson <andy.arvid at gmail.com> wrote:
> If you use a let within the init-form of an outer let, the result is invalid
> javascript code.
>
> Here is a simplified example:
>
> (ps (let ((x (let ((y (a)))
>        (b)
>                y)))
>       (1+ x)))
>
> ==>
>
> "(function () {
>     var y;
>     var x = (y = a(), (b(), y));
>     return x + 1;
> })();"
>
> Not that I would normally write such code, but the inner "let" was generated
> by a macro.
> And many macros use "let" with gensyms.  In my case, the macro used
> "ps-once-only".
>
> Andy Peterson
>
> _______________________________________________
> parenscript-devel mailing list
> parenscript-devel at common-lisp.net
> http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
>




More information about the parenscript-devel mailing list