(define mapper (lambda (key val) (emit-words (string-tokenize key)))) (define emit-words (lambda (words) (if (null? words) #f (begin (wmr-emit (car words) "1") (emit-words (cdr words))))))
(define reducer (lambda (key vals) (wmr-emit key (reduce-values 0 vals)))) (define reduce-values (lambda (sum vals) (if (stream-null? vals) sum (reduce-values (+ sum (string->number (stream-car vals))) (stream-cdr vals)))))