Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Actually included my iterate extensions. Also extended the averaging …
…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
Showing
2 changed files
with
9 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters