1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-10 00:00:39 -08:00

Refix conditional step clauses in cl-loop

* lisp/emacs-lisp/cl-macs.el
(cl--loop-bindings, cl--loop-symbol-macs, cl-loop):
Add cl--loop-conditions, remove cl--loop-guard-cond.
(cl--push-clause-loop-body): Apply clause to both cl--loop-conditions
and cl--loop-body
(cl--parse-loop-clause): Use cl--push-clause-loop-body.
* test/lisp/emacs-lisp/cl-macs-tests.el (cl-macs-loop-and-assignment):
Use docstring.
(cl-macs-loop-for-as-arith): Removed expected failure.
(cl-macs-loop-conditional-step-clauses): Add some tests (bug#29799).
This commit is contained in:
dickmao 2019-11-22 15:53:58 +01:00 committed by Lars Ingebrigtsen
parent f373cec7f5
commit 045cfbef09
2 changed files with 101 additions and 63 deletions

View file

@ -30,7 +30,7 @@
;;; ANSI 6.1.1.7 Destructuring
(ert-deftest cl-macs-loop-and-assignment ()
;; Bug#6583
"Bug#6583"
:expected-result :failed
(should (equal (cl-loop for numlist in '((1 2 4.0) (5 6 8.3) (8 9 10.4))
for a = (cl-first numlist)
@ -61,7 +61,6 @@
;;; 6.1.2.1.1 The for-as-arithmetic subclause
(ert-deftest cl-macs-loop-for-as-arith ()
"Test various for-as-arithmetic subclauses."
:expected-result :failed
(should (equal (cl-loop for i to 10 by 3 collect i)
'(0 3 6 9)))
(should (equal (cl-loop for i upto 3 collect i)
@ -74,9 +73,9 @@
'(10 8 6)))
(should (equal (cl-loop for i from 10 downto 1 by 3 collect i)
'(10 7 4 1)))
(should (equal (cl-loop for i above 0 by 2 downfrom 10 collect i)
(should (equal (cl-loop for i downfrom 10 above 0 by 2 collect i)
'(10 8 6 4 2)))
(should (equal (cl-loop for i downto 10 from 15 collect i)
(should (equal (cl-loop for i from 15 downto 10 collect i)
'(15 14 13 12 11 10))))
(ert-deftest cl-macs-loop-for-as-arith-order-side-effects ()
@ -530,4 +529,65 @@ collection clause."
l)
'(1))))
(ert-deftest cl-macs-loop-conditional-step-clauses ()
"These tests failed under the initial fixes in #bug#29799."
(should (cl-loop for i from 1 upto 100 and j = 1 then (1+ j)
if (not (= i j))
return nil
end
until (> j 10)
finally return t))
(should (equal (let* ((size 7)
(arr (make-vector size 0)))
(cl-loop for k below size
for x = (* 2 k) and y = (1+ (elt arr k))
collect (list k x y)))
'((0 0 1) (1 2 1) (2 4 1) (3 6 1) (4 8 1) (5 10 1) (6 12 1))))
(should (equal (cl-loop for x below 3
for y below 2 and z = 1
collect x)
'(0 1)))
(should (equal (cl-loop for x below 3
and y below 2
collect x)
'(0 1)))
;; this is actually disallowed in clisp, but is semantically consistent
(should (equal (cl-loop with result
for x below 3
for y = (progn (push x result) x) and z = 1
append (list x y) into result1
finally return (append result result1))
'(2 1 0 0 0 1 1 2 2)))
(should (equal (cl-loop with result
for x below 3
for _y = (progn (push x result))
finally return result)
'(2 1 0)))
;; this nonintuitive result is replicated by clisp
(should (equal (cl-loop with result
for x below 3
and y = (progn (push x result))
finally return result)
'(2 1 0 0)))
;; this nonintuitive result is replicated by clisp
(should (equal (cl-loop with result
for x below 3
and y = (progn (push x result)) then (progn (push (1+ x) result))
finally return result)
'(3 2 1 0)))
(should (cl-loop with result
for x below 3
for y = (progn (push x result) x) then (progn (push (1+ x) result) (1+ x))
and z = 1
collect y into result1
finally return (equal (nreverse result) result1))))
;;; cl-macs-tests.el ends here