Are you saying that foo.txt has two newlines at the end in your version?
I think that this is probably just how read-line works and your
function inherits it:
#lang racket
(parameterize ([current-input-port
(open-input-string
"first line\n\nthird line\n")])
(list (read-line)
(read-line)
(read-line)
(read-line)))
(parameterize ([current-input-port
(open-input-string
"first line\n\nthird line")])
(list (read-line)
(read-line)
(read-line)
(read-line)))
On Sat, Apr 16, 2016 at 11:02 AM, Matthias Felleisen
<[email protected]> wrote:
> I added a newline at the end (using via) between the two expressions:
>
>
> Welcome to DrRacket, version 6.5.0.1--2016-04-12(-/f) [3m].
> Language: racket, with debugging.
>> (read-words/line "foo.txt")
> '(("hello") () ("world"))
>> (read-words/line "foo.txt")
> '(("hello") () ("world") ())
>
>
>
>> On Apr 16, 2016, at 7:55 AM, Robby Findler <[email protected]>
>> wrote:
>>
>> When I run this program on my mac, I get the output that Quico
>> predicts (i.e., the two return the same thing and there is no
>> terminating empty list).
>>
>> #lang racket
>> (require 2htdp/batch-io)
>> (parameterize ([current-input-port
>> (open-input-string
>> "first line\n\nthird line\n")])
>> (read-words/line 'stdin))
>>
>> (parameterize ([current-input-port
>> (open-input-string
>> "first line\n\nthird line")])
>> (read-words/line 'stdin))
>>
>> Robby
>>
>>
>> On Sat, Apr 16, 2016 at 9:32 AM, Matthias Felleisen
>> <[email protected]> wrote:
>>>
>>> I cannot reproduce this behavior on my Mac 10.11. After reading the code of
>>> the library, I also don’t see why Linux should behave differently. The
>>> file’s history also doesn’t show a problem report concerning this issue. —
>>> Matthias
>>>
>>>
>>>
>>>
>>>> On Apr 15, 2016, at 9:39 PM, Quico Jurado <[email protected]> wrote:
>>>>
>>>> Hello, I posted this question in SO, but hoping to get more answers here.
>>>>
>>>> I'm reading Part two from the 2htdp book, and I'm curious about the
>>>> behavior of the read-words/line function that lives under 2htdp/batch-io.
>>>>
>>>> I created two different files, the first file having a \n at the end of
>>>> the file and the second file without it, like this:
>>>>
>>>> echo -ne "first line\n\nthird line\n" > file1.txt
>>>> echo -ne "first line\n\nthird line" > file2.txt
>>>>
>>>> if I read each one of the files with the read-words/line, this is the
>>>> result:
>>>>
>>>> (read-words/line "doc/book/htdp2/data/file1.txt")
>>>> ; => '(("first" "line") () ("third" "line"))
>>>>
>>>> (read-words/line "doc/book/htdp2/data/file2.txt")
>>>> ; => '(("first" "line") () ("third" "line"))
>>>>
>>>> It looks that the function isn't preserving the information from the last
>>>> newline character in the first file.
>>>>
>>>> Is that behavior intended?
>>>>
>>>> I'm Running Dr Racket 6.2.1 on a GNU/Linux box.
>>>>
>>>> Thanks,
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google Groups
>>>> "Racket Users" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send an
>>>> email to [email protected].
>>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Racket Users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to [email protected].
>>> For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.