<div>The error I see when evaluating your third example is happening because your LOOP..DO is being used as an expression (it's a branch of an IF form which is an argument to the POST function). This is illegal because LOOP..DO compiles to a statement in JS, not an expression. Here's a shorter version of the error:</div>
<div><br></div><div> (ps (foo (loop for i from 0 to len do (bar))))</div><div> => compiler error</div><div><br></div><div>Note that using LOOP..COLLECT instead of LOOP..DO does work, but only because PS goes to the trouble of wrapping it an a lambda that then gets called to return the collection:</div>
<div><br></div><div>(ps (foo (loop for i from 0 to len collect (bar))))</div><div> =></div><div><br></div><div><div>"foo((function () {</div><div> var collect52 = [];</div><div> for (var i = 0; i <= len; i += 1) {</div>
<div> collect52.push(bar());</div><div> };</div><div> return collect52;</div><div>})());"</div></div><div><br><div><div>PS treats these two cases differently because LOOP..COLLECT (and its relatives like LOOP..SUM) are clearly "expressiony" while LOOP..DO isn't; wrapping the latter in a lambda isn't justifiable in the general case.</div>
<div><br></div><div>Does this help?</div><div><br></div><div>Daniel</div><div><br></div><div><div><br><div class="gmail_quote">On Wed, Mar 23, 2011 at 10:13 AM, F D <span dir="ltr"><<a href="mailto:dubfa@hotmail.com" target="_blank">dubfa@hotmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
Hello,<br><br>I'm trying to convert my js strings into parenscript code but I've a problem.<br><br>1) This works<br>(ps::ps <br> (ps::chain $ <br> (post jsonServerUrl <br> (if (ps::@ data error)<br>
(alert (ps::@ data error))<br> (progn<br> (alert "test1")<br> (alert "test2")<br> )))))<br>
2) This works<br>
(ps::ps<br> (if (ps::@ data error)<br> (alert (ps::@ data error))<br> (loop for i from 0 to arLen<br> do<br> (ps::chain newil <br> (setAttribute "class" <br> (if (= (ps::@ (ps:getprop data i) typedonnee) "tabgrouptype")<br>
"ui-state-default" <br> "ui-state-default no-nest")) <br><br> ))))<br><br>3) but this doesn't work (the if clause of first example if replaced by the if clause of the second one)<br>
(ps::ps<br> (ps::chain $ <br> (post jsonServerUrl <br> (if (ps::@ data error)<br> (alert (ps::@ data error))<br> (loop for i from 0 to arLen<br> do<br>
(ps::chain newil <br> (setAttribute "class" <br> (if (= (ps::@ (ps:getprop data i) typedonnee) "tabgrouptype")<br>
"ui-state-default" <br> "ui-state-default no-nest")) <br> ))))))<br>
<br>Is there something wrong with my code?<br><br>Thanks<br><br>FD<br><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></div>