Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

converting a file to list or string in scheme

Tags:

scheme

racket

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?

like image 570
Ceelos Avatar asked May 05 '12 23:05

Ceelos


2 Answers

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

like image 93
wedesoft Avatar answered Nov 10 '22 17:11

wedesoft


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.

like image 29
Asumu Takikawa Avatar answered Nov 10 '22 16:11

Asumu Takikawa