From 14668c3805d5147784366ea1266cb64436a57cab Mon Sep 17 00:00:00 2001 From: Corder Guy Date: Sun, 10 Mar 2024 17:50:54 -0500 Subject: [PATCH] rutils.iter: fix defclause-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. --- core/iter.lisp | 2 +- test/iter-test.lisp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/iter.lisp b/core/iter.lisp index 196c702..4a87964 100644 --- a/core/iter.lisp +++ b/core/iter.lisp @@ -2000,7 +2000,7 @@ the body of the loop, so it must not contain anything that depends on the body." (seq-code (or seq-var sequence)) (step-var (unless (constant? by) (make-var-and-default-binding 'step :type 'fixnum))) - (step (or step-var by)) + (step (or step-var by 1)) (step-func (if (or downto downfrom above) '- '+)) (test-func (cond (to '>) ((or downto downfrom) '<) diff --git a/test/iter-test.lisp b/test/iter-test.lisp index f8c8c4c..8d0a30c 100644 --- a/test/iter-test.lisp +++ b/test/iter-test.lisp @@ -5,3 +5,7 @@ (cl:in-package #:rutils.test) (named-readtables:in-readtable rutils-readtable) +(deftest iter () + (should be equal '(#\a #\b #\c) + (iter (:for c :in-string "abc") + (:collect c))))