On Saturday, April 16, 2016 at 4:20:16 PM UTC-6, Robby Findler wrote:
> And in response to Quico, I would say that what's happening here is
> that read-line (and therefore read-words/line) are interpreting a
> "line" to be a bunch of characters followed by a specific set of
> delimiters (a newline in the examples in this thread). And so if you
> have a file with "a\nb" then that is one line and one partial line.
> Since the file ends, then read-line just decides to act as if there
> were a fully terminated line at the end of the file.
> 
> Robby

Thanks for all the helpful responses.

I guess this make sense to me (partially). Probably the user has to have in 
mind how this works, since this could be source of confusion for some new 
users; like in the case of counting lines. If we use the two same files from 
the original example, using `wc' from the GNU coreutils, one would expect to 
get 3 lines and 2 lines respectively:

    wc -l data/file1.txt
      # => 3 data/file1.txt
    wc -l data/file2.txt                                                  
      # => 2 data/file2.txt

on the other hand, if the user tries to count the number of lines based on the 
structure returned by `read-words/line' it would return 3 for both cases. 
    
    (length (read-words/line "data/file1.txt"))
      ; => 3
    (length (read-words/line "data/file2.txt"))
      ; => 3

Probably it would be a good idea to document this behavior so it doesn't 
surprises the new user.

Also, one of the responses from Matthias caught my attention where he mentioned 
that he wasn't able to reproduce this on his Mac.

Cheers,

-- 
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 racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to