Subject: Re: Load and execute
From: (Rob Warnock)
Date: 1998/05/06
Newsgroups: comp.lang.scheme
Message-ID: <6ipibe$>

Frank Cieslok <> wrote:
| I'm looking for a way to load and execute a scheme file in a way that
| the result of the executed code is returned to the caller. If for
| example the file 'blub.scm' contains just '42', the code
|	(define answer (load "blub.scm"))
| should set 'answer' to '42'. R5RS told me that the 'load' procedure
| doesn't do that.

It doesn't, but if your Scheme has an "eval", you might be able to do
something like this [leaving out the 2nd arg to "eval" in older Schemes]:

	> (define (load/value fname)
	    (with-input-from-file fname
	      (lambda ()
		(let loop ((sexpr (read))
			   (result #f))
		  (if (eof-object? sexpr)
		    (loop (read) (eval sexpr (interaction-environment))))))))

	> (load/value "blub.scm")


Rob Warnock, 7L-551
Silicon Graphics, Inc.		Phone: 650-933-1673 [New area code!]
2011 N. Shoreline Blvd.		FAX: 650-933-4392
Mountain View, CA  94043	PP-ASEL-IA