147d800c551e

Simplify `averaging`
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Mon, 19 Sep 2016 23:55:12 +0000
parents 75229fb62b8c
children 6aec014eb591
branches/tags (none)
files losh.lisp

Changes

--- a/losh.lisp	Sun Sep 18 14:04:29 2016 +0000
+++ b/losh.lisp	Mon Sep 19 23:55:12 2016 +0000
@@ -692,15 +692,12 @@
     (0.1 0.1 0.13333334 0.17500001 0.22)
 
   "
-  (with-gensyms (count)
+  (with-gensyms (count total)
     (let ((average (or var iterate::*result-var*)))
       `(progn
-        (for ,count :from 0)
-        (for ,average
-             :first ,expr
-             :then (/ (+ (* ,average ,count)
-                         ,expr)
-                      (1+ ,count)))))))
+        (for ,count :from 1)
+        (sum ,expr :into ,total)
+        (for ,average = (/ ,total ,count))))))
 
 (defmacro-clause (TIMING time-type &optional
                   SINCE-START-INTO since-var