david135 / mosh-scheme

Automatically exported from code.google.com/p/mosh-scheme
Other
0 stars 0 forks source link

Reading nothing from a port returns eof #169

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

$ cat zeroport.ss 
(import (rnrs) (srfi :48))

(define i1 (open-bytevector-input-port #vu8(102 111 111)))
(define i2 (open-string-input-port "foo"))
(define i3 (make-custom-textual-input-port "i3" (lambda (s x t) (display 
"foo\n") 0) #f #f #f))

(display (format "get-bytevector-n : ~s~%" (get-bytevector-n i1 0)))
(display (format "get-string-n     : ~s~%" (get-string-n i2 0)))
(display (format "custom-text-port : ~s~%" (get-string-n i3 0)))
$ mosh zeroport.ss 

What is the expected output? What do you see instead?

I saw
get-bytevector-n : #<eof-object>
get-string-n     : #<eof-object>
custom-text-port : #<eof-object>

I expected
get-bytevector-n : #vu8()
get-string-n     : ""
custom-text-port : ""

What version of the product are you using? On what operating system?

Mosh 0.25 and Mosh commit a3e9df9e510cf57e345c8a1d8321facf07670d4c on Fedora 13

Please provide any additional information below.

The R6RS states that the count argument to get-bytevector-n and get-string-n 
must be an exact *non-negative* integer object and that they should return a 
bytevector/string consisting of that number of characters. Therefore, 
(get-bytevector-n port 0) should return an empty bytevector, and (get-string-n 
port 0) should return an empty string, not an eof object. Even in the case that 
the next u8/char to be read would result in an eof, i.e. (get-char 
(open-string-input-port "")), it should return an empty bytevector/string as 
zero bytes/characters are *always* available.

One note about the custom port. The R6RS states that the count argument to the 
'read!' procedure of a custom input port will be a positive exact integer 
object, therefore it is my understanding that (get-[bytevector/string]-n port 
0) should *not* invoke the read! procedure (which Mosh does not do), but should 
return #vu8/"" as mentioned above.

The behaviour of 'zeroport.ss' on Ikarus 0.0.4-rc1, Racket v5.0, Larceny 0.97, 
and Ypsilon 0.9.6-trunk/r503 is as follows
$ ikarus --r6rs-script zeroport.ss 
get-bytevector-n : #vu8()
get-string-n     : ""
custom-text-port : ""
$ plt-r6rs zeroport.ss 
get-bytevector-n : #""
get-string-n     : ""
custom-text-port : ""
$ larceny -r6rs -program zeroport.ss 
get-bytevector-n : #vu8()
get-string-n     : ""
custom-text-port : ""
$ ypsilon zeroport.ss 
get-bytevector-n : #vu8()
get-string-n     : ""
custom-text-port : ""

Original issue reported on code.google.com by ianpric...@gmail.com on 3 Sep 2010 at 12:07

GoogleCodeExporter commented 9 years ago
One other data point
$ mosh
mosh> (define i (open-string-input-port "foo"))
#<unspecified>
mosh> (get-string-n i 0)
#<eof-object>
mosh> (get-string-n i 3)
"foo"

This is just plain wrong IMO

Original comment by ianpric...@gmail.com on 3 Sep 2010 at 12:11

GoogleCodeExporter commented 9 years ago
Fixed and added test.
http://github.com/higepon/mosh/commit/b851eaef6184ba0d9c51fc1caae5a5cde98fcc05

Thanks.

Original comment by hige...@gmail.com on 4 Sep 2010 at 5:22