Skip to content

Commit

Permalink
Actually included my iterate extensions. Also extended the averaging …
Browse files Browse the repository at this point in the history
…reduction

clause to handle initial values, different addition and division ops.  This is
useful for, say, averaging vectors, or performing geometric means,
what-have-you.
  • Loading branch information
smithzvk committed May 23, 2011
1 parent 0386c16 commit 0fca237
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
12 changes: 8 additions & 4 deletions iterate.lisp
@@ -1,14 +1,18 @@

(in-package :toolbox)

(iter:defmacro-clause (average expr)
(iter:defmacro-clause (average expr
&optional
by (addition-op '#'+)
using-divisor (division-op '#'/)
initially (initial-value 0) )
(let ((total (gensym))
(count (gensym)) )
`(progn
(with ,total = 0)
(with ,total = ,initial-value)
(with ,count = 0)
(incf ,total ,expr)
(setf ,total (funcall ,addition-op ,total ,expr))
(incf ,count)
(finally (return (/ ,total ,count))) )))
(finally (return (funcall ,division-op ,total ,count))) )))

(iter:defsynonym averaging average)
1 change: 1 addition & 0 deletions toolbox.asd
Expand Up @@ -7,6 +7,7 @@
:components ((:file "package")
(:file "on")
(:file "anaphoric")
(:file "iterate")
(:file "dbind")
(:file "applied")
(:file "mvb")
Expand Down

0 comments on commit 0fca237

Please sign in to comment.