I think the issue is that `read-line` is returning a string, so in every
iteration of the for loop line is bound to a single character from that
string, I think you may want to use `in-lines`[1] instead of `read-line`.

[1]:
http://docs.racket-lang.org/reference/sequences.html?q=in-lines#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._in-lines%29%29

On Thu, Dec 17, 2015 at 2:19 AM, Mark Thom <markjordant...@gmail.com> wrote:

> As an exercise, I'm implementing a simple grep function in Racket:
>
> (define (grep-file pattern . files)
>   (for ([file-path (in-list files)])
>     (with-input-from-file file-path #:mode 'text
>       (lambda ()
>         (for ([line (read-line (current-input-port) 'return-linefeed)]
>               [i (in-naturals 1)])
>           (match line
>             [(regexp pattern)
>              (printf "~D : ~S~%" i line)]
>             [else (printf "~S~%" line)]))))))
>
> I expect that read-line should read properly terminated lines from files.
> Instead, each value of line in the inner for is a single character from
> the file.
>
> I can't seem to find any mention of a similar problem online, or reproduce
> it in any other context. The same behavior follows regardless of whether
> the file is DOS or Unix formatted.
>
> I'm running Racket 6.2.1 on Windows 7. 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 racket-users+unsubscr...@googlegroups.com.
> 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 racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to