Implementation of cumulate added by DeeEff on Fri Aug 19 00:03:25 2016

(define (cumulate proc knil s)
  (let loop ([knil knil]
             [head (car s)]
             [tail (cdr s)]
             [acc '()])
    (if (null? tail)
      (reverse (cons (proc head knil) acc))
      (let ([val (proc head knil)])
        (loop val
              (car tail)
              (cdr tail)
              (cons val acc))))))