Verified Commit cf4cab20 authored by Vladimir Sedach's avatar Vladimir Sedach
Browse files

Bind DOLIST/DOTIMES var to nil before evaluating result form

parent 5262b5fd
......@@ -395,7 +395,8 @@ lambda-list::=
(defpsmacro dotimes ((var count &optional (result nil result?)) &rest body)
`(do* ((,var 0 (1+ ,var)))
((>= ,var ,count) ,@(when result? (list result)))
((>= ,var ,count)
,@(when result? `((let ((,var nil)) ,result))))
,@body))
(defpsmacro dolist ((var array &optional (result nil result?)) &body body)
......@@ -409,7 +410,7 @@ lambda-list::=
(list (list arrvar array)))
(,idx 0 (1+ ,idx)))
((>= ,idx (getprop ,arrvar 'length))
,@(when result? (list result)))
,@(when result? `((let ((,var nil)) ,result))))
(setq ,var (aref ,arrvar ,idx))
,@body)))
......
......@@ -61,7 +61,7 @@
(test-js-eval empty-array
(array)
'())
#())
(test-js-eval funargs-let1
((lambda (x)
......@@ -910,3 +910,13 @@
3)
(setf x (+ 2 (side-effect) x 5)))
14)
(test-js-eval dolist-result-bind-nil
(dolist (i '(1 2 3) (list i 9))
(list i))
'(nil 9))
(test-js-eval dotimes-result-bind-nil
(dotimes (i '(1 2 3) (list 9 i))
(list i))
'(9 nil))
......@@ -554,6 +554,7 @@ return alert('Summation to 10 is ' + (function () {
for (var i = 0; i < 10; i += 1) {
res += i + 1;
};
var i = null;
return res;
})());
})();")
......@@ -584,6 +585,7 @@ return alert('Sum of ' + l + ' is: ' + (function () {
c = l[_js_idx1];
s += c;
};
var c = null;
return s;
})());
})();")
......
......@@ -48,12 +48,13 @@
(ps-doc* ',parenscript)))))))
(defun js-repr (x)
(if (listp x)
(cl-js:js-array
(make-array (length x)
:initial-contents (mapcar #'js-repr x)
:adjustable t))
x))
(cond ((or (consp x) (simple-vector-p x))
(cl-js:js-array
(make-array (length x)
:initial-contents (map 'vector #'js-repr x)
:adjustable t)))
((null x) :null)
(t x)))
(defmacro %test-js-eval (testname parenscript test-statement)
`(fiveam:test ,testname ()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment