Subject: Re: Loading file as function
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 1999/08/10
Newsgroups: comp.lang.scheme
Message-ID: <7oqa56$3utnu@fido.engr.sgi.com>
forcer  <forcer@mindless.com> wrote:
+---------------
| I'm implementing a load replacement that caches files. For this,
| i want to write a function which reads in a file, and makes it a
| function that, when called, duplicates the actions of loading the file.
...
| Does anyone have an idea on how to implement this in a better way?
+---------------

What's wrong with this?

	(define (my-load filename)
	  (with-input-from-file filename
	    (lambda ()
	      (do ((form (read) (read)))
		  ((eof-object? form))
		(eval form (interaction-environment))))))

Then you can put your cache hooks in as you see fit. But... Be careful!

1. Scheme's top-level "define" doesn't have the same distinctions available
   as Common Lisp's "defvar/defparameter" (see <URL:http://www.harlequin.com/
   education/books/HyperSpec/Body/mac_defparametercm_defvar.html> for the
   details). You're going to have to have some way of indicating which of
   those behaviors you want (that is, leave the var alone if already bound,
   or stomp it unconditionally, respectively).

2. Also, you'll need a way to "mark" a file as non-cacheable, say,
   whenever a top-level form in that file involves non-idempotent
   side-effects...


-Rob

-----
Rob Warnock, 8L-855		rpw3@sgi.com
Applied Networking		http://reality.sgi.com/rpw3/
Silicon Graphics, Inc.		Phone: 650-933-1673
1600 Amphitheatre Pkwy.		FAX: 650-933-0511
Mountain View, CA  94043	PP-ASEL-IA