Ceelos
Ceelos

Reputation: 1126

converting a file to list or string in scheme

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?

Upvotes: 10

Views: 11134

Answers (2)

Asumu Takikawa
Asumu Takikawa

Reputation: 8523

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.

Upvotes: 16

wedesoft
wedesoft

Reputation: 2989

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

Upvotes: 7

Related Questions