Hi, I am new to chicken and got stuck trying to do buffered inter-process communication. Could someone give me a hint why in the sample code below `copy_b` freezes whereas `copy_c` works as expected? Thanks!
#!/usr/bin/env -S csi -s (import (chicken process) (chicken io) srfi-1) (define cmd "/usr/bin/env") ;; copy process out/error to current out/error ports (call-with-values (lambda () (process* cmd)) (lambda (in out pid err) (close-output-port out) (letrec (;; copy string (copy_b (lambda (pair) (let ((i (car pair)) (o (cdr pair))) (let ((s (read-buffered i))) (if (eof-object? s) (close-input-port i) (write-string s (string-length s) o)))))) ;; copy char (copy_c (lambda (pair) (let ((i (car pair)) (o (cdr pair))) (when (char-ready? i) (let ((c (read-char i))) (if (eof-object? c) (close-input-port i) (write-char c o))))))) ;; recurse over list of port pairs (iter (lambda (alist) (unless (null? alist) (for-each copy_b alist) ; <-- copy_? gets called here (iter (filter (lambda (pair) (input-port-open? (car pair))) alist)))))) (iter (list (cons in (current-output-port)) (cons err (current-error-port)))))))