Skip to content

Commit 64be9b6

Browse files
Merge pull request #47 from dfmorrison/parallel-iter-csv
"move special bindings just around reader construction, fixing issues #43 and #44
2 parents bbded0d + c3481ea commit 64be9b6

File tree

5 files changed

+25
-7
lines changed

5 files changed

+25
-7
lines changed

csv.lisp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
((format-control :accessor format-control :initarg :format-control :initform nil)
1414
(format-args :accessor format-args :initarg :format-args :initform nil))
1515
(:report (lambda (c s &aux (ctrl (format-control c)))
16-
(typecase ctrl
16+
(typecase ctrl
1717
(condition
1818
(format s "CSV-PARSE-ERROR: internal-error ~A" ctrl))
1919
(string
@@ -245,10 +245,10 @@ always-quote: Defaults to *always-quote*"
245245
;; can't bind values in a `with`, so listify and destructure
246246
(with (,stream ,opened?) = (multiple-value-list
247247
(%in-stream ,input)))
248-
(with *separator* = (or ,separator *separator*))
249-
(with *quote* = (or ,quote *quote*))
250-
(with *quote-escape* = (or ,escaped-quote *quote-escape*))
251-
(with ,csv-reader = (make-default-csv-reader))
248+
(with ,csv-reader = (let ((*separator* (or ,separator *separator*))
249+
(*quote* (or ,quote *quote*))
250+
(*quote-escape* (or ,escaped-quote *quote-escape*)))
251+
(make-default-csv-reader)))
252252
(finally-protected
253253
(when (and ,stream ,opened?)
254254
(close ,stream)))
@@ -349,7 +349,7 @@ body: body of the macro"
349349
(stream-or-string
350350
&rest all-keys
351351
&key
352-
csv-reader row-fn map-fn data-map-fn sample skip-first-p
352+
csv-reader row-fn map-fn data-map-fn sample skip-first-p
353353
((:separator *separator*) *separator*)
354354
((:quote *quote*) *quote*)
355355
((:escape *quote-escape*) *quote-escape*)

tests/csv.lisp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,19 @@ multiline" (nth 3 (first data)) ))
260260
(assert-equal "5" b)
261261
(assert-equal "6" c)
262262
(for i from 0)
263-
(finally (assert-equal 0 i))))
263+
(finally (assert-equal 0 i)))
264+
265+
;; test multiple files
266+
(assert-equal '(("1" "a" "2" "b") ("3" "c" "4" "d"))
267+
(iter (for (x y) in-csv #P"numbers.csv")
268+
(for (u v) in-csv #P"letters.csv")
269+
(collect (list x u y v))))
270+
271+
;; test nested reads
272+
(assert-equal '(("1" (("a" "b") ("c" "d")) "2") ("3" (("a" "b") ("c" "d")) "4"))
273+
(iter (for (x y) in-csv #P"numbers.txt" separator #\Tab)
274+
(collect (list x (read-csv #P"letters.csv") y)))))
275+
264276

265277
(define-test sampling-iterate (:tags '(sampling iterate))
266278
(assert-length

tests/letters.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
a,b
2+
c,d

tests/numbers.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1,2
2+
3,4

tests/numbers.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1 2
2+
3 4

0 commit comments

Comments
 (0)