Skip to content

Commit

Permalink
Fixing make/with-collector so that this function should be more compl…
Browse files Browse the repository at this point in the history
…ient

Collector functions (as by make-collector) no longer return their arguments
which makes their item list dynamic-extent.

From the spec:
The value of a rest parameter is permitted, but not required, to share
structure with the last argument to apply.

We saw no actual bugs with this, but it seemed prudent to fix it before
we did
  • Loading branch information
bobbysmith007 committed Feb 1, 2012
1 parent db2c950 commit 9727ab2
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions collectors.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,18 @@ A Collector function will collect, into a list, all the values
passed to it in the order in which they were passed. If the
callector function is called without arguments it returns the
current list of values."
(let ((value initial-value)
(cdr (last initial-value)))
;; by using this head cons cell we can simplify the loop body
(let* ((head (cons :head (copy-list initial-value)))
(cdr (last head)))
(lambda (&rest items)
(unless collect-nil (setf items (delete-if #'null items)))
(if items
(progn
(if value
(if cdr
(setf (cdr cdr) items
cdr (last items))
(setf cdr (last items)))
(setf value items
cdr (last items)))
items)
value))))
(declare (dynamic-extent items))
(if (null items)
(cdr head)
(loop for i in items
when (or collect-nil i)
do (let ((new-cons (cons i nil)))
(setf (cdr cdr) new-cons
cdr new-cons)))))))

(defun make-appender (&optional initial-value)
"Create an appender function.
Expand Down

0 comments on commit 9727ab2

Please sign in to comment.