chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] read-line (and probably other input routines) - unexpect


From: $)
Subject: [Chicken-users] read-line (and probably other input routines) - unexpected behaviour when reading binary files on Windows
Date: Tue, 17 Oct 2006 13:42:25 +0400



---------- Forwarded message ----------
From: $) <address@hidden>
Date: 17.10.2006 13:30
Subject: read-line (and probably other input routines) - unexpected behaviour when reading binary files on Windows
To: address@hidden

Hi!
The Chicken manual says that read-line consumes all input from the current input port untill #!eof when called without parameters.
The weird thing is that Scheme IO treats #\x1a (character with code 27) as #!eof when reading from file. The following code snippet prints #!eof:

(define crash-pattern "\x1a (esc) breaks read-line \x1a it is weird")
(with-output-to-file "test.scm.123" (lambda() (display crash-pattern)))
(print(with-input-from-file "test.scm.123 " read-line))

The file "test.scm.123" is written successfully. So I guess that something goes wrong while reading the file?

With-input-from-string or even reading from custom port behaves as expected:

(define crash-pattern "\x1a (esc) breaks read-line and read-string \x1a it is weird")
(define (my-make-string-port str)
 (let* (
    (str str)
    (index -1)
    (indexlt (string-length str)))
 (make-input-port 
    (lambda() (set! index(+ 1 index)) (if (< index indexlt) (string-ref str index) #!eof))
    (lambda() #t)
    (lambda() (void)) )))

(print (with-input-from-string crash-pattern read-line)) ; doen't trim crash-pattern
(print (with-input-from-port (my-make-string-port crash-pattern) read-line)) ; doesn't trim crash-pattern as well

I wonder if this behaviour is by design? Are there any issues related to reading and writing binary data with ports in Chicken Scheme?

WBR, mejedi
Sedna team

reply via email to

[Prev in Thread] Current Thread [Next in Thread]