[racket] read text file

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Mon Dec 6 21:48:14 EST 2010

Try file->string

Jay

On Mon, Dec 6, 2010 at 7:43 PM, prad <prad at towardsfreedom.com> wrote:

> i'm trying to read a text file into a string, sort of like
>
> readFile path -- in haskell
> or
> handle = open(path, 'r'); data = handle.read() # in python
>
> however, in the guide
> open-input-file
> call-with-input-file
> all use read-line
>
> in lisp i could get the length of the stream and slurp the whole file
> in:
> (defun slurp (path)
>  "one way of reading in files"
>  (with-open-file (stream path)
>    (let ((seq (make-array (file-length stream)
>                           :element-type 'character)))
>      (read-sequence seq stream)
>      seq)))
>
> but what am i supposed to in racket?
> (other than read-line right through to the end of the file, may be?)
>
> or is reading it all in at one shot not considered the right way to do
> it here?
>
> --
> In friendship,
> prad
>
>                                      ... with you on your journey
> Towards Freedom
> http://www.towardsfreedom.com (website)
> Information, Inspiration, Imagination - truly a site for soaring I's
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
>



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20101206/4a26b7f9/attachment.html>

Posted on the users mailing list.