6740e201e636

Fix concatenating to handle separators properly
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Mon, 24 May 2021 01:05:42 -0400
parents 91ea751ccd9f
children 8a7cfee11dea
branches/tags (none)
files src/iterate.lisp

Changes

--- a/src/iterate.lisp	Mon May 24 01:05:13 2021 -0400
+++ b/src/iterate.lisp	Mon May 24 01:05:42 2021 -0400
@@ -675,7 +675,8 @@
   a fresh string each time or whether an adjustable string is mutated is
   implementation defined.
 
-  If `separator` is not `nil`, it must be a string designator.
+  If `separator` is not `nil` it must be a string designator, and it will be
+  evaluated once at the beginning of the iterate form.
 
   Examples:
 
@@ -718,11 +719,12 @@
     (let ((sos (gensym "SOS"))
           (sep (gensym "SEP")))
       `(progn
-         (with ,sos = (make-string-output-stream))
+         (with ,sos = nil)
          (with ,sep = ,(if separator (string separator) nil))
-         (if-first-time
-           nil
-           (when ,sep (write-string ,sep ,sos)))
+         (if (null ,sos)
+           (setf ,sos (make-string-output-stream))
+           (when ,sep
+             (write-string ,sep ,sos)))
          (write-string ,expr ,sos)
          (finally (return (get-output-stream-string ,sos)))))))