Take the 2-minute tour ×

I'm having a bit of an issue taking a text file and converting it into a list or string.

Say I have "blah.txt" which holds:

3 + 4

Now I want to call that file which I know can be done by

(define in (open-input-file "blah.txt"))

Where do I take it from here?

share|improve this question
The leading quote in the question doesn't look right. I expected (define in (open-input-file "blah.txt")). Please confirm. –  dyoo May 6 '12 at 0:09
Oh yeah, My mistake. didn't mean to put that quotation mark. It should've read (define in(open-input-file "blah.txt")) –  Ceelos May 6 '12 at 3:00
Ok, good. I'll edit the question accordingly without the quote. Good luck! –  dyoo May 6 '12 at 20:10

2 Answers 2

up vote 4 down vote accepted

Take a look at the file->list function or file->lines, which should do what you want in Racket. That is, something like (file->lines "blah.txt") will give you a list of lines from the file. More generally, look at the guide entry on I/O.

share|improve this answer
THANK YOU! THAT DID IT! : ) –  Ceelos May 6 '12 at 0:23

Given a file name, file->string loads the file and returns the content as a string.

share|improve this answer
This link is dead. Consider updating it if you can. –  BlackVegetable May 3 at 16:23
Ok, I updated the link –  wedesoft Jul 2 at 16:57

Your Answer


