;; read-to-list ;; Sid Stamm (c) 2003 ;; takes a read-int procedure, an input port (open) and a max ;; number of iterations. ;; read-to-list applies proc to the port up to max times ;; or until the #!eof is returned from proc. ;; ;; Example usage: ;; (read-to-list read-int p 10) ;; (define read-to-list (lambda (proc ip max-times) (let loop ([acc '()] [val (proc ip)] [i 0]) (if (= max-times i) (begin (printf "Maximum Iterations reached~%") (reverse acc)) (if (eof-object? val) (reverse (cons #!eof acc)) (loop (cons val acc) (proc ip) (add1 i)))))))