Skip to content

Commit 0e8b548

Browse files
committed
rutils.iter: fix defcaluse-sequence drivers
Defaults `step` in `return-seq-code` to 1. Currently, all drivers that use `defclause-sequence` are broken, because `step` is not bound before `return-sequence-code` is called. This results in `step` being bound to nil, which means `initial-value` is set to `(- nil)` and `step-code` is set to something like `(+ index nil)`. This change causes `step` to default to 1 if it is not provided.
1 parent 79cb029 commit 0e8b548

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

core/iter.lisp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2000,7 +2000,7 @@ the body of the loop, so it must not contain anything that depends on the body."
20002000
(seq-code (or seq-var sequence))
20012001
(step-var (unless (constant? by)
20022002
(make-var-and-default-binding 'step :type 'fixnum)))
2003-
(step (or step-var by))
2003+
(step (or step-var by 1))
20042004
(step-func (if (or downto downfrom above) '- '+))
20052005
(test-func (cond (to '>)
20062006
((or downto downfrom) '<)

test/iter-test.lisp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@
55
(cl:in-package #:rutils.test)
66
(named-readtables:in-readtable rutils-readtable)
77

8+
(deftest iter ()
9+
(should be equal '(#\a #\b #\c)
10+
(iter (:for c :in-string "abc")
11+
(:collect c))))

0 commit comments

Comments
 (0)