Re: Weird behaviour of SRFI-127 lseq in a multithreaded program
Stanislav Kljuhhin via Chicken-users <[email protected]> Sun, 22 Feb 2026 22:08:24 +0100
| Newsgroups | gmane.lisp.scheme.chicken |
|---|---|
| Message-ID | <[email protected]> |
OK, I should probably have figured this out earlier myself. The egg sources are not entirely up-to-date with upstream and miss this commit: https://github.com/scheme-requests-for-implementation/srfi-127/commit/7976fce401da8ac368ada1914c5fbaba715aa246 https://srfi-email.schemers.org/srfi-127/msg/21875262/ — Stan > On 22 Feb 2026, at 20:20, Kon Lovett <[email protected]> wrote: > > ;; Eagerly apply a proc to the elements of lseqs > ;; Included because it's a common operation, even though it is trivial > (define (lseq-for-each proc . lseqs) > (apply for-each proc (map lseq-realize lseqs))) > > lseq-for-each* applies the proc before processing the remaining list, not the egg source. > > >> On Feb 22, 2026, at 10:22 AM, Stanislav Kljuhhin via Chicken-users <[email protected]> wrote: >> >> Hello, >> >> Consider the following minimal example: >> >> ---8<--- >> (import srfi-18) >> (import srfi-121) >> (import srfi-127) >> >> (define (emit yield) >> (let loop ((i 1)) >> (thread-sleep! 1) >> (yield "hello") >> (when (< i 10) >> (loop (add1 i))))) >> >> (define (collect s) >> (display s) >> (newline)) >> >> (define (lseq-for-each* proc lseq) >> (unless (null? lseq) >> (proc (lseq-car lseq)) >> (lseq-for-each* proc (lseq-cdr lseq)))) >> >> (lseq-for-each collect (generator->lseq (make-coroutine-generator emit))) >> ---8<—-- >> >> When I run this program (compiled or interpreted, makes no difference), nothing >> happens for 10 seconds, then 10 hello's are printed at once. But if I use the >> in-place implementation lseq-for-each*, then the program behaves as one might >> expect, i.e. hello's are printed with a 1-second interval. >> >> Here I used a simplified implementation of lseq-for-each*, just for brevity, but >> we can copy the SRFI-127 implementation verbatim, and it still works the same. >> >> Can you help me understand what is going on, please? >> >> — >> Stan >