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.
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@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@common-lisp.net http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
thanks. Finally I wrap it inside a lambda. Is it a good idea for parenscript to automatically wrap LOOPs inside a lambda when compiling a loop as a expression?
On Mon, Sep 5, 2011 at 11:40 AM, Daniel Gackle danielgackle@gmail.com wrote:
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@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@common-lisp.net http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
parenscript-devel mailing list parenscript-devel@common-lisp.net http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
parenscript-devel@common-lisp.net