<div class="gmail_quote">On Wed, Sep 9, 2009 at 4:37 PM, Doug Williams <span dir="ltr">&lt;<a href="mailto:m.douglas.williams@gmail.com">m.douglas.williams@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Thanks for running them for me.  I guess it comes down to whether the flexibility is worth the performance hit. I like the flexibility. In the past there were times I have had to convert lists to vectors just to compute statistics on them, which is even less efficient.  I could include the old ones as vector-mean, vector-variance, etc for people who need/want the performance.<br>
<font color="#888888">
<br>Doug</font><div><div></div><br></div></blockquote><div><br>Why not special case for vectors instead of adding to the module interface?<br></div></div><br>(define (mean data)<br>  (if (vector? data) (vector-mean data) (generic-mean data))<br>
<br>(define (generic-mean data)<br>  (for/fold ((m-old 0.0))<br>            ((i (in-naturals))<br>             (x data))<br>    (+ m-old (/ (- x m-old) (add1 i)))))<br><pre>(<span class="keyword">define</span> (<span class="variable">vector-mean</span> <span class="variable">data</span>)<br>
  (<span class="keyword">let</span> ((<span class="variable">n</span> (<span class="builtin">vector-length</span> <span class="variable">data</span>))<br>        (<span class="variable">mu</span> <span class="selfeval">0.0</span>))<br>
    (<span class="keyword">do</span> ((<span class="variable">i</span> <span class="selfeval">0</span> (<span class="builtin">+</span> <span class="variable">i</span> <span class="selfeval">1</span>)))<br>        ((<span class="builtin">=</span> <span class="variable">i</span> <span class="variable">n</span>) <span class="variable">mu</span>)<br>
      (<span class="keyword">set!</span> <span class="variable">mu</span> (<span class="builtin">+</span> <span class="variable">mu</span> (<span class="builtin">/</span> (<span class="builtin">-</span> (<span class="builtin">vector-ref</span> <span class="variable">data</span> <span class="variable">i</span>) <span class="variable">mu</span>) (<span class="builtin">+</span> <span class="variable">i</span> <span class="selfeval">1</span>)))))))<br>
</pre>--<br>Marco<br>