(use-modules (ice-9 q) (srfi srfi-1)) (define (avg n xs) (/ (fold + 0 xs) n)) (define (ma subn xs) (define q (make-q)) (set-car! q (take xs subn)) (sync-q! q) (let l ((xs (drop xs subn)) (avgs (make-q))) (enq! avgs (avg subn (car q))) (if (null? xs) (car avgs) (begin (q-pop! q) (enq! q (car xs)) (l (drop xs 1) avgs)))))
See all the discussions around the web about this page.