The line (displayln (/ (+ prior current next))) needs to be changed to <div> (displayln (/ (+ prior current next) 3))</div><div><br></div><div>Thanks,<br><div><br><div class="gmail_quote">On Sat, May 26, 2012 at 9:20 PM, Matthias Felleisen <span dir="ltr"><<a href="mailto:matthias@ccs.neu.edu" target="_blank">matthias@ccs.neu.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Do you mean that if you operated on a list it would look like this:<br>
<br>
#lang racket<br>
<br>
(define (running-average-of-3 l2)<br>
(define-values (_1 _2)<br>
(for/fold ((current (second l2)) (prior (first l2))) ((next (rest (rest l2))))<br>
(displayln (/ (+ prior current next)))<br>
(values next current)))<br>
(void))<br>
<br>
(running-average-of-3 '(1 2 3 4 5 6 7 8 9 0))<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
<br>
On May 26, 2012, at 12:56 AM, Harry Spier wrote:<br>
<br>
> I can use for/fold to loop through a sequence while having the current<br>
> element and the previous element of the sequence still available by<br>
> doing something like this.<br>
><br>
> (for/fold ([previous-element-in-sequence '()][list-being-created '()])<br>
> ( [current-element-in-sequence sequence])<br>
> (do some stuff)<br>
> ....<br>
> (values current-element-in-sequence<br>
> (cons something list-being-created)))<br>
><br>
> But what I want is to be able to loop through a sequence while having<br>
> the prior, the current and the next element available.<br>
><br>
> I'm sequencing through a representation of lines of a black and white<br>
> page of text showing where the black pixels are and from that<br>
> producing a graph showing the connectivity of the black pixel strips<br>
> on each line to the ones on the lines above and below it.<br>
><br>
> Using for/fold I'm able to code the graph of connectedness of the<br>
> black strips on each line to the prior line in a very straightforward<br>
> way, but I'd like to graph in both directions both to the prior line<br>
> and to the next line at the same time.<br>
><br>
> Is there a simple way to loop through a sequence and have the prior,<br>
> current and next element available at the same time.<br>
><br>
> Thanks,<br>
> Harry<br>
> ____________________<br>
> Racket Users list:<br>
> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br>
<br>
____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</div></div></blockquote></div><br></div></div>