3

I am new to to guile and scheme and what I am trying to do right now is take a scheme file (file.scm) and load it up into a variable so I will be able to parse it, and I am having trouble finding how to do this anywhere.

What I have right now is

(define var (load "file.scm")) ; loads file scheme

but I am unsure how to start reading the lines.

Ryan w
  • 528
  • 1
  • 7
  • 21

2 Answers2

5

load parses and runs the scheme code in a file. If you just want to read a file, use open-input-file.

(define file (open-input-file "file address here"))
(display (read-line file))
merlyn
  • 2,273
  • 1
  • 19
  • 26
1

If you just want to read an entire file as a string, there's a function for that in the textual-ports module. You'd use it something like:

(define contents (call-with-input-file "file.txt" get-string-all))

(You can use call-with-input-file and with-input-from-file to avoid having to manually open and close a file port, which is handy)

Shawn
  • 47,241
  • 3
  • 26
  • 60