diff options
author | Leah Neukirchen <leah@vuxu.org> | 2022-10-30 17:57:25 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2022-10-30 17:57:25 +0100 |
commit | c703c1170def0cf0a41282a713665ac91847f7da (patch) | |
tree | dc2f198d1f5c16f985443c4c7254d43b032b309f | |
parent | fec64041bc4dde07cf3c8fb87c3cf0a1a1dac28f (diff) | |
download | mew-c703c1170def0cf0a41282a713665ac91847f7da.tar.gz mew-c703c1170def0cf0a41282a713665ac91847f7da.tar.xz mew-c703c1170def0cf0a41282a713665ac91847f7da.zip |
add gslice-when
-rw-r--r-- | mew.scm | 26 | ||||
-rw-r--r-- | mew.svnwiki | 6 |
2 files changed, 32 insertions, 0 deletions
diff --git a/mew.scm b/mew.scm index 1644436..d05f8bb 100644 --- a/mew.scm +++ b/mew.scm @@ -283,6 +283,32 @@ (set! window (append (cdr window) (list next))) window))))))) + (define (gslice-when pred gen) + (let ((slice #f) + (prev #f) + (this #f)) + (lambda () + (unless slice + (set! prev (gen)) + (when (eof-object? prev) + (set! this (eof))) + (set! slice (list prev))) + (if (eof-object? this) + this + (let loop () + (set! this (gen)) + (if (eof-object? this) + (reverse slice) + (if (pred prev this) + (let ((finished-slice (reverse slice))) + (set! slice (list this)) + (set! prev this) + finished-slice) + (begin + (set! slice (cons this slice)) + (set! prev this) + (loop))))))))) + (define (genumerate gen) (let ((n -1)) (lambda () diff --git a/mew.svnwiki b/mew.svnwiki index 511ee54..2339394 100644 --- a/mew.svnwiki +++ b/mew.svnwiki @@ -218,6 +218,12 @@ Generator yielding a sliding window of length {{<len>}} (as a list) over the values yielded by the generator {{<gen>}}. Yields never if the generator yielded fewer than {{<len>}} elements. +<procedure>(gslice-when <pred> <gen>)<procedure> + +Partition the elements yielded by the generator {{<gen>}} into lists: +starts a new list when the predicate {{<pred>}} called with the +previous and the current element of the generator returns true. + <procedure>(genumerate <gen>)<procedure> Takes the values yielded by the generator {{<gen>}} and yields them as |