Using guile 1.8 or guile 2, the following code reads past EOF, seemingly for a few extra lines, then stops. The effect this has in the larger program of which this is an extract is to seemingly corrupt the previously read data. Am I using read-line or testing for eof-object incorrectly?
(use-modules (ice-9 rdelim))
(define f
(lambda (p)
(let loop ((line (read-line p)))
(format #t "line: ~a\n" line)
(if (not (eof-object? (peek-char p)))
(begin
(let ((m (string-match "^[ \t]*#" line)))
(if m
(begin
(format #t "comment: ~a\n" (match:string m))
(loop (read-line p))
)))
(format #t "read next line\n")
(loop (read-line p)))))))
(define main
(lambda ()
(let ((h (open-input-file "test")))
(f h))))
Here is a minimal sample dummy input file:
1
2
3
# comment line
4
5
1
2
3
# comment line
4
5
1
2
3
# comment line
4
5
It needs to be more than a few lines long for the problem to manifest. Apologies for the length of the code example, but the issue only arises when the code gets to this amount of complexity (albeit small).