(define (read-file filename) (define (loop) (let ((line (read-line))) (if (eof-object? line) '() (cons line (loop))))) (with-input-from-file filename loop)) ;this works: (define (read-file2) (with-input-from-file "stuff.txt" (lambda () (let loop ((line (read))) (unless (eof-object? line) (print line) (newline) (loop (read))))))) ;this works (it's a helper function): (define (iterate finished? producer consumer) (let loop ((product (producer))) (unless (finished? product) (consumer product) (loop (producer))))) ;this works (define (read-file3) (with-input-from-file "stuff.txt" (lambda () (iterate eof-object? read (lambda (line) (print line) (newline)))))) (define (read-file4) (with-input-from-file "stuff.txt" (lambda () (let loop ( (line #f)) (set! line (read)) (unless (eof-object? line) (print line) (newline) (loop #t))))))