[parenscript-devel] Loops that return a value

Boris Smilga boris.smilga at gmail.com
Thu Jan 17 14:10:23 UTC 2013

By the way, David's request led me to experiment with different  
looping constructs in PS, and in the process I noticed that the  
behaviour of DOLIST diverges from its Common Lisp prototype when used  
with a RESULT-FORM that references the iteration variable.  E. g.:

   (dolist (i '(1 2 3) (foo i)) (foo i))

expands to

   (function () {
       for (var i = null, _js_arrvar58 = [1, 2, 3], _js_idx57 = 0;  
_js_idx57 < _js_arrvar58.length; _js_idx57 += 1) {
           i = _js_arrvar58[_js_idx57];
       return foo(i);

Since JavaScript variables have at least function scope, this  
effectively evaluates to foo(3), excluding side effects.

On the other hand, CLHS entry for DOLIST (§6.2) contains the  
following clause:

   dolist (var list-form [result-form]) declaration* {tag | statement}*

   At the time RESULT-FORM is processed, VAR is bound to NIL.

Given this project's goal, stated by Vladimir in a recent message, of  
bringing PS semantically as close as possible to Lisp, this  
discrepancy is rather unfortunate, so please find attached a patch to  
remove it.

  — B. Smilga.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Set-iteration-var-to-null-when-evaluating-result-of-dolist.patch
Type: application/octet-stream
Size: 1126 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/parenscript-devel/attachments/20130117/d7da3779/attachment.obj>

More information about the parenscript-devel mailing list