Vladmir,<div><br></div><div>Thanks for the detailed response.  I can see you are right.  Now I am totally confused why I got the error a month ago in google chrome as I can not recreate it. I swear I tested my original example. I remember writing an function a and b and testing. On top of that, the original macro I wrote now seems to work within a let.</div>
<div><br></div><div>Anyway, this is the original macro for a "functional-pseudo-chain":</div><div><div><font face="courier new, monospace">(defpsmacro fpchain (object &rest chains)</font></div><div><font face="courier new, monospace">  "generate a pseudo-chain of method calls of given object</font></div>
<div><font face="courier new, monospace">and return the object. for use of js prototypes that do not</font></div><div><font face="courier new, monospace">allow chaining like j-query."</font></div><div><font face="courier new, monospace">  (ps-once-only (object)</font></div>
<div><font face="courier new, monospace">    (append '(progn)</font></div><div><font face="courier new, monospace">            (mapcar (lambda (x) `(chain ,object ,x))</font></div><div><font face="courier new, monospace">                    chains)</font></div>
<div><font face="courier new, monospace">            `(,object))))</font></div></div><div><font face="courier new, monospace"><br></font></div><div><font face="arial, helvetica, sans-serif">I use this primarily for the html5 canvas context object which requires a lot of method calls in a row but does not allow chaining.</font></div>
<div><font face="arial, helvetica, sans-serif">Similar to ps:chain except for the fact it does not chain properties  (fpchain foo bar (baz)) does not work.</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div>
<div><font face="arial, helvetica, sans-serif">thanks again,</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">andy peterson</font></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Thu, Nov 29, 2012 at 12:31 AM, 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">
Believe it or not, that's actually valid JavaScript code:<br>
<br>
PS> (ps (let ((x (let ((y 12))<br>
                   (+ 1 2)<br>
                   y)))<br>
      (1+ x)))<br>
"(function () {<br>
    var y;<br>
    var x = (y = 12, (1 + 2, y));<br>
<div class="im">    return x + 1;<br>
})();"<br>
</div>PS> (cl-js:run-js *)<br>
13<br>
<br>
In your example, a() and b() were expressions, so the inner let<br>
generated a sequence of expressions by using the comma operator. If<br>
for example you replace b() by a statement:<br>
<br>
PS> (ps (let ((x (let ((y 12))<br>
                (dolist (x '(1 2 3))<br>
                  (* x x))<br>
                y)))<br>
       (1+ x)))<br>
"(function () {<br>
    var y;<br>
    var x4 = (y = 12, ((function () {<br>
        for (var x = null, _js_arrvar6 = [1, 2, 3], _js_idx5 = 0;<br>
_js_idx5 < _js_arrvar6.length; _js_idx5 += 1) {<br>
            x = _js_arrvar6[_js_idx5];<br>
            x * x;<br>
        };<br>
    })(), y));<br>
    return x4 + 1;<br>
})();"<br>
PS> (cl-js:run-js *)<br>
13<br>
<br>
This is ugly, and I would love examples of how to generate better code<br>
for nested LETs.<br>
<br>
Happy hacking,<br>
Vladimir<br>
<div><div class="h5"><br>
<br>
On Wed, Oct 24, 2012 at 5:50 AM, Andy Peterson <<a href="mailto:andy.arvid@gmail.com">andy.arvid@gmail.com</a>> wrote:<br>
> If you use a let within the init-form of an outer let, the result is invalid<br>
> javascript code.<br>
><br>
> Here is a simplified example:<br>
><br>
> (ps (let ((x (let ((y (a)))<br>
>        (b)<br>
>                y)))<br>
>       (1+ x)))<br>
><br>
> ==><br>
><br>
> "(function () {<br>
>     var y;<br>
>     var x = (y = a(), (b(), y));<br>
>     return x + 1;<br>
> })();"<br>
><br>
> Not that I would normally write such code, but the inner "let" was generated<br>
> by a macro.<br>
> And many macros use "let" with gensyms.  In my case, the macro used<br>
> "ps-once-only".<br>
><br>
> Andy Peterson<br>
><br>
</div></div>> _______________________________________________<br>
> parenscript-devel mailing list<br>
> <a href="mailto:parenscript-devel@common-lisp.net">parenscript-devel@common-lisp.net</a><br>
> <a href="http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel" target="_blank">http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel</a><br>
><br>
<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://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel" target="_blank">http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel</a><br>
</blockquote></div><br></div>