[parenscript-devel] question about dolist

Daniel Gackle danielgackle at gmail.com
Mon Sep 5 03:40:26 UTC 2011


PS is complaining because DOLIST compiles to a FOR loop in JS and FOR
loops can't be used as expressions, only statements. You might argue
that this case is a bug, since the DOLIST isn't in the tail position
of the LET form and so needn't be treated as an expression,
i.e. perhaps the compiler ought to transform your code into this:

  (let ((x 0))
    (dolist (i '(1 2 3))
      (incf x i))
    (setf v x))

But for now you have to write the above yourself, or else wrap your
DOLIST in a lambda (and call that lambda).

Loops are one of the areas where JS tends to trump the Lispiness of PS.

Daniel

On Sun, Sep 4, 2011 at 8:57 PM, Canhua <dreameration at gmail.com> wrote:

> hi, I found that the following compiles to an error, I wonder if this
> is a bug or there is something I misunderstand.
>    (ps (setf v
>              (let ((x 0))
>                (dolist (i '(1 2 3))
>                  (incf x i))
>                x)))
> where the error is:
>
>  The Parenscript form (for
>                      (i (#1=_js_arrvar467 '(1 2 3))
>                       (#2=_js_idx466 0))
>                      ((not (>= #2# #))) ((setf #2# #))
>                      (setq i (aref #1# #2#)) (incf x i)) cannot be
> compiled into an expression.
>   [Condition of type compile-expression-error]
>
> Hope you help me, thank you.
>
> _______________________________________________
> parenscript-devel mailing list
> parenscript-devel at common-lisp.net
> http://lists.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/20110904/662b0417/attachment.html>


More information about the parenscript-devel mailing list