Re: [racket-users] Example of file i/o?

2017-07-19 Thread Leith
That's exactly what I was trying to do - thanks!

On Wed, Jul 19, 2017 at 12:26 PM, Greg Hendershott <
greghendersh...@gmail.com> wrote:

> If you frequently want to deal with files as a list of lines, you
> could wrap the code Ben showed you in a function:
>
> (define (file->lines file)
>   (with-input-from-file file
> (λ ()
>   (for/list ([line (in-lines)])
> line
>
> As it happens, Racket already defines this function for you:
>
>   https://docs.racket-lang.org/reference/Filesystem.html#%
> 28def._%28%28lib._racket%2Ffile..rkt%29._file-~3elines%29%29
>

-- 
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.


Re: [racket-users] Example of file i/o?

2017-07-18 Thread Leith
Very good, thank you!

On Tuesday, July 18, 2017 at 11:54:14 AM UTC-5, Ben Greenman wrote:
> (with-input-from-file "file.txt"
>   (lambda ()
>     (for ((line (in-lines)))
>       )))
> 
> 
> On Tue, Jul 18, 2017 at 12:46 PM, Leith <leit...@gmail.com> wrote:
> Basic question, but I can't seem to find a good answer.  What is an example 
> of "idiomatic" file I/O using racket?  Like, for example, open a file for 
> reading and do something with every line in the file?
> 
> 
> 
> The example here: https://docs.racket-lang.org/guide/io-patterns.html  says 
> "If you want to process individual lines of a file" but then it doesn't open 
> a file at all.  It uses open-input-string.  I'm guessing it would be 
> sufficient to use open-input-file instead?  Also, what is the right way to 
> read a line at a time until EOF?
> 
> 
> 
> 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...@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.


[racket-users] Example of file i/o?

2017-07-18 Thread Leith
Basic question, but I can't seem to find a good answer.  What is an example of 
"idiomatic" file I/O using racket?  Like, for example, open a file for reading 
and do something with every line in the file?

The example here: https://docs.racket-lang.org/guide/io-patterns.html  says "If 
you want to process individual lines of a file" but then it doesn't open a file 
at all.  It uses open-input-string.  I'm guessing it would be sufficient to use 
open-input-file instead?  Also, what is the right way to read a line at a time 
until EOF?

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.