656f2f6975bc

Fix separator in `concatenating` iterate macro
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Tue, 14 Dec 2021 19:10:21 -0500
parents 7a3907583b2d
children c2970d9e6ea7
branches/tags (none)
files src/iterate.lisp

Changes

--- a/src/iterate.lisp	Tue Dec 14 19:09:58 2021 -0500
+++ b/src/iterate.lisp	Tue Dec 14 19:10:21 2021 -0500
@@ -709,9 +709,11 @@
 
   "
   (if var
-    (let ((sep (gensym "SEP")))
+    (let ((separator% (gensym "SEPARATOR"))
+          (sep (gensym "SEP")))
       `(progn
-         (with ,sep = ,(if separator (string separator) ""))
+         (with ,separator% = ,separator)
+         (with ,sep = (if ,separator% (string ,separator%) ""))
          (reducing ,expr
                    :by (lambda (a b)
                          (if (null a)
@@ -719,11 +721,15 @@
                            (concatenate 'string a ,sep b)))
                    :into ,var
                    :initial-value nil)))
-    (let ((sos (gensym "SOS"))
+    (let ((separator% (gensym "SEPARATOR"))
+          (sos (gensym "SOS"))
           (sep (gensym "SEP")))
       `(progn
+         (with ,separator% = ,separator)
          (with ,sos = nil)
-         (with ,sep = ,(if separator (string separator) nil))
+         (with ,sep = (if (or (null ,separator%) (equal ,separator% ""))
+                        nil
+                        (string ,separator%)))
          (if (null ,sos)
            (setf ,sos (make-string-output-stream))
            (when ,sep