<div dir="ltr">I think I understand the following example from the documentation:<div><br></div><div><div>(define (example)</div><div> (for/fold ([sum 0]</div><div> [averages null]) ;; 2 accums named sum and rev-roots are initialized</div>
<div> ([i '(1 2 3 4)]) ;; i will iterate over 1..4</div><div> (values </div><div> (+ sum i) ;; adding to sum</div><div> (cons (sqrt i) averages) ;; consing to rev-roots</div>
<div> )))</div><div><br></div><div>(example) -></div><div>10</div><div>'(2 1.7320508075688772 1.4142135623730951 1)</div></div><div><br></div><div><br></div><div>But I realize I don't really understand when I try the following:</div>
<div><br></div><div><div>(define (example2)</div><div> (for/fold ([sum 0]</div><div> [averages null])</div><div> ([i '(1 2 3 4)])</div><div> (values </div><div> (+ sum i) ;; adding to sum</div>
<div> (cons (/ sum i) averages) ;; record running average but sum is not what I think it should be</div><div> )))</div></div><div><br></div><div>(example2) -></div><div><div>10</div><div>'(1 1/2 1 1/2 0)</div>
</div><div><br></div><div>Not reducing for readability, I was hoping for</div><div>(10/4 6/3 3/2 1)</div><div><br></div><div>How can I tweak the code?</div><div><br></div><div>jGc</div></div>