[racket] Looping with look-behind and look-forward
On Sun, May 27, 2012 at 8:46 AM, Harry Spier <vasishtha.spier at gmail.com> wrote:
> (define (f1 l)
> (for/fold ([result-list '()])
> ( [prior (in-list (append '() l))]
> [x (in-list l)]
> [next (in-list (append (rest l) '()))])
> ...
> ... make new-result-element using x prior and next...
> (cons new-result-element result-list))
> (reverse result-list))
If you don't need result-list in the body of the for you can
use for/list which looks a bit simpler.
(define (f1 l)
(for/list ([prior (in-list (append '() l))]
[x (in-list l)]
[next (in-list (append (rest l) '()))])
...
... make new-result-element using x prior and next...))
Cheers,
Sam