Subject: Re: Load and execute
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 1998/05/06
Newsgroups: comp.lang.scheme
Message-ID: <6ipibe$ecp0@fido.asd.sgi.com>

Frank Cieslok <frankc@sallust.ida.ing.tu-bs.de> 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)
		    result
		    (loop (read) (eval sexpr (interaction-environment))))))))

	> (load/value "blub.scm")
	42
	> 


-Rob

-----
Rob Warnock, 7L-551		rpw3@sgi.com   http://reality.sgi.com/rpw3/
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