Skip to content

Commit

Permalink
when using place, default initial-value to place as well
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbysmith007 committed Jan 10, 2014
1 parent 08e6a27 commit e45f541
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions collectors.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Example:
FUNCTION and INITIAL-VALUE are passed directly to MAKE-REDUCER."
(alexandria:with-unique-names (reducer)
`(let ((,reducer (make-reducer ,function
:initial-value ,initial-value
:initial-value (or ,initial-value ,place)
:place-setter ,(when place `(lambda (new) (setf ,place new))))))
(flet ((,name (&rest items) (apply ,reducer items)))
,@body))))
Expand Down Expand Up @@ -140,7 +140,7 @@ current list of values."
"
(alexandria:with-unique-names (appender)
`(let ((,appender (make-appender
:initial-value ,initial-value
:initial-value (or ,initial-value ,place)
:place-setter ,(when place `(lambda (new) (setf ,place new))))))
(flet ((,name (&rest items) (apply ,appender items)))
,@body))))
Expand All @@ -167,7 +167,7 @@ current list of values."
`(let ((,collector (,(if from-end
'make-pusher
'make-collector)
:initial-value ,initial-value
:initial-value (or ,initial-value ,place)
:collect-nil ,collect-nil
:place-setter ,(when place `(lambda (new) (setf ,place new))))))
(flet ((,name (&rest items)
Expand Down
34 changes: 17 additions & 17 deletions tests/collectors.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -127,32 +127,32 @@
(assert-equal '(2 2 4 2 4 6 2 4 6 8) (test))))

(define-test reducer-place (:tags '(place reducer))
(let (reduced)
(let ((reduced 1))
(with-reducer (r #'+ :place reduced)
(r 0)
(assert-equal 0 reduced)
(assert-equal 1 (r 1))
(assert-equal 1 reduced)
(assert-equal 6 (r 2 3))
(assert-equal 6 reduced))))
(assert-equal 2 (r 1))
(assert-equal 2 reduced)
(assert-equal 7 (r 2 3))
(assert-equal 7 reduced))))

(define-test appender-place (:tags '(place appender))
(let (appended)
(let ((appended '(:A)))
(with-appender (a :place appended)
(a 0)
(assert-equal '(0) appended)
(assert-equal '(0 1) (a 1))
(assert-equal '(0 1) appended)
(assert-equal '(0 1 2 3 4) (a '(2 3) '(4)))
(assert-equal '(0 1 2 3 4) appended))))
(assert-equal '(:A 0) appended)
(assert-equal '(:A 0 1) (a 1))
(assert-equal '(:A 0 1) appended)
(assert-equal '(:A 0 1 2 3 4) (a '(2 3) '(4)))
(assert-equal '(:A 0 1 2 3 4) appended))))

(define-test collector-place (:tags '(place collector))
(let (collected)
(let ((collected '(:A)))
(with-collector (c :place collected)
(c 0)
(assert-equal '(0) collected)
(assert-equal '(0 1) (c 1))
(assert-equal '(0 1) collected)
(assert-equal '(0 1 (2 3) (4)) (c '(2 3) '(4)))
(assert-equal '(0 1 (2 3) (4)) collected))))
(assert-equal '(:a 0) collected)
(assert-equal '(:a 0 1) (c 1))
(assert-equal '(:a 0 1) collected)
(assert-equal '(:a 0 1 (2 3) (4)) (c '(2 3) '(4)))
(assert-equal '(:a 0 1 (2 3) (4)) collected))))

0 comments on commit e45f541

Please sign in to comment.