[parenscript-devel] what's wrong?

Daniel Gackle danielgackle at gmail.com
Thu Mar 24 04:34:34 UTC 2011


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:

  (ps (foo (loop for i from 0 to len do (bar))))
      => compiler error

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:

(ps (foo (loop for i from 0 to len collect (bar))))
     =>

"foo((function () {
    var collect52 = [];
    for (var i = 0; i <= len; i += 1) {
        collect52.push(bar());
    };
    return collect52;
})());"

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.

Does this help?

Daniel


On Wed, Mar 23, 2011 at 10:13 AM, F D <dubfa at hotmail.com> wrote:

>  Hello,
>
> I'm trying to convert my js strings into parenscript code but I've a
> problem.
>
> 1) This works
> (ps::ps
>   (ps::chain $
>              (post jsonServerUrl
>                    (if (ps::@ data error)
>                        (alert (ps::@ data error))
>                      (progn
>                        (alert "test1")
>                        (alert "test2")
>                        )))))
> 2) This works
> (ps::ps
>   (if (ps::@ data error)
>       (alert (ps::@ data error))
>     (loop for i from 0 to arLen
>           do
>           (ps::chain newil
>                      (setAttribute "class"
>                                    (if (= (ps::@ (ps:getprop data i)
> typedonnee) "tabgrouptype")
>                                        "ui-state-default"
>                                      "ui-state-default
> no-nest"))
>
>                      ))))
>
> 3) but this doesn't work (the if clause of first example if replaced by the
> if clause of the second one)
> (ps::ps
>   (ps::chain $
>              (post jsonServerUrl
>                    (if (ps::@ data error)
>                        (alert (ps::@ data error))
>                      (loop for i from 0 to arLen
>                            do
>                            (ps::chain newil
>                                       (setAttribute "class"
>                                                     (if (= (ps::@(ps:getprop data i) typedonnee) "tabgrouptype")
>                                                         "ui-state-default"
>                                                       "ui-state-default
> no-nest"))
>                                       ))))))
>
> Is there something wrong with my code?
>
> Thanks
>
> FD
>
>
> _______________________________________________
> parenscript-devel mailing list
> parenscript-devel at common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/parenscript-devel/attachments/20110323/f175a8f0/attachment.html>


More information about the parenscript-devel mailing list