summary refs log tree commit diff
path: root/mew.scm
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2022-12-12 23:02:11 +0100
committerLeah Neukirchen <leah@vuxu.org>2022-12-16 00:12:57 +0100
commit8be1e42cfbf9e3bc9d64dc839969d4b4293afb53 (patch)
tree9c4d49279f83565999a712582514a9d3489932e7 /mew.scm
parent0c5dec75a7c68ca69384bbc27f8a273976de92d1 (diff)
downloadmew-8be1e42cfbf9e3bc9d64dc839969d4b4293afb53.tar.gz
mew-8be1e42cfbf9e3bc9d64dc839969d4b4293afb53.tar.xz
mew-8be1e42cfbf9e3bc9d64dc839969d4b4293afb53.zip
add nth-accumulator
Diffstat (limited to 'mew.scm')
-rw-r--r--mew.scm12
1 files changed, 11 insertions, 1 deletions
diff --git a/mew.scm b/mew.scm
index f95c0b1..259f51c 100644
--- a/mew.scm
+++ b/mew.scm
@@ -14,7 +14,7 @@
      keys
      len lines loc
      mod
-     negate
+     negate nth-accumulator
      odometer one-of op op*
      per prn proj puts
      rand range rep
@@ -936,6 +936,16 @@
                  (hash-table-values items)
                  (hash-table-update!/default items (f x) identity x)))))))
 
+  (define (nth-accumulator n)
+    (let ((n n) (state (void)))
+      (lambda (x)
+        (if (eof-object? x) 
+           state
+           (begin
+             (when (zero? n)
+               (set! state x))
+             (set! n (dec n)))))))
+
   (define (generator-xfold f seed . gs)
     (define (inner-xfold seed)
       (let ((vs (map (lambda (g) (g)) gs)))