[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: newbie: read, load and eval

From: Mike Gran
Subject: Re: newbie: read, load and eval
Date: Sun, 22 Oct 2006 01:34:15 -0700 (PDT)

Let's say you had a file "" that contained

("This" "is" "a" "test")

Note that there is no initial quote.

One way would be 

(display (read (open-input-file "")))

but this doesn't explicity close the file "" right after the call, which 
might be an issue if you are opening a lot of files.

One step up could be

(call-with-input-file ""  (lambda (p) (display (read p))))

This will explicity close the file after it is read.

Note that this specifically reads exactly one s-expression from the top of the 
file, as you requested.  It might be simpler to have an "" that contained 
a bunch of (define) statements, like so

(define a '("This" "is" "a" "test"))

Then you could (load "") that file, and the defined variables would be 

Hope this helps,

Mike Gran

----- Original Message ----
From: "address@hidden" <address@hidden>
To: address@hidden
Sent: Saturday, October 21, 2006 11:48:04 PM
Subject: newbie: read, load and eval

This seems like the simplest thing which guile ought to be able to do
in a snap, but I can't for the life of me work out how to do it.

I have a file called which contains some data as a scheme
expression, such as

'("This" "is" "a" "test")

and I want to use these data in a program, so I want to write a line

(display (load ""))

but it doesn't work; nor does

(with-input-from-file "" (lambda () (display (read))))

What is the way to do this?

Guile-user mailing list

reply via email to

[Prev in Thread] Current Thread [Next in Thread]