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

2017-07-19 Thread Neil Van Dyke
Since newbies are always listening, I'll just mention something a lot of people here (including Greg) already know. :) Something like `file->lines` is a handy convenience, when you know the file size won't break your system, and/or you're not writing reusable or long-lived code. Good

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

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

2017-07-19 Thread Greg Hendershott
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:

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 wrote: > Basic question, but I can't seem

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

2017-07-18 Thread Ben Greenman
(with-input-from-file "file.txt" (lambda () (for ((line (in-lines))) ))) On Tue, Jul 18, 2017 at 12:46 PM, Leith 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,

[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