a guest Dec 19th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (define tbatch
  2.   (case-lambda
  3.     ((reducer)
  4.      (tbatch null-transducer reducer))
  5.     ((t r)
  6.      (lambda (reducer)
  7.        (let ((cur-reducer (t r))
  8.              (cur-state (r)))
  9.          (case-lambda
  10.            (() (reducer))
  11.            ((result) (reducer result))
  12.            ((result value)
  13.             (let ((val (cur-reducer cur-state value)))
  14.               (cond
  15.                ;; cur-reducer is done. Push value downstream
  16.                ;; re-instantiate the state and the cur-reducer
  17.                ((reduced? val)
  18.                 (let ((unreduced-val (unreduce val)))
  19.                   (set! cur-reducer (t r))
  20.                   (set! cur-state (cur-reducer))
  21.                   (reducer result (cur-reducer unreduced-val))))
  22.                (else
  23.                 (set! cur-state val)
  24.                 result))))))))))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand