Permalink
Browse files

Ported Arnesi's #'MAKE-COLLECTOR

  • Loading branch information...
1 parent 848c524 commit 355efb73b14cb09e45de0563631ee933fbc75f0b @adlai committed Sep 1, 2009
Showing with 27 additions and 1 deletion.
  1. +2 −1 src/package.lisp
  2. +25 −0 src/utils.lisp
View
@@ -2,7 +2,8 @@
(defpackage :Eos
(:use :common-lisp :it.bese.arnesi)
- (:shadow #:ensure-list #:aif #:partitionx #:with-unique-names #:list-match-case)
+ (:shadow #:ensure-list #:aif #:make-collector #:partitionx
+ #:with-unique-names #:list-match-case)
(:export ;; creating tests and test-suites
#:make-suite
#:def-suite
View
@@ -14,6 +14,31 @@
`(let ((it ,test))
(if it ,true ,false)))
+;;; This is taken from Arnesi's src/accumulation.lisp, and is way
+;;; too complicated for its simple use here.
+
+(defun make-collector (&optional initial-value)
+ "Create a collector function.
+
+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)))
+ (lambda (&rest 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))))
+
;;; This is taken from Arnesi's src/list.lisp, and partitions
;;; a list into separate parts using predicate lambdas

0 comments on commit 355efb7

Please sign in to comment.