Path: utzoo!attcan!uunet!wuarchive!udel!princeton!phoenix!eliot From: eliot@phoenix.Princeton.EDU (Eliot Handelman) Newsgroups: comp.lang.lisp Subject: Re: scope/extent interaction with flet and load Message-ID: <3642@idunno.Princeton.EDU> Date: 28 Oct 90 03:06:40 GMT References: <60375@bbn.BBN.COM> <1990Oct26.133156@cs.yale.edu> <332@puma.ge.com> Sender: news@idunno.Princeton.EDU Distribution: comp Organization: Shitson University, New Crapsey Lines: 53 In article <332@puma.ge.com> kmorgan@fergie.UUCP (Keith Morgan) writes: ;In article <1990Oct26.133156@cs.yale.edu> engelson-sean@cs.yale.edu (Wisp Lizard) writes: ; ;> To do ;>what you want with functions, you need to change the global function ;>definition, as follows: ;> >(let ((old+ #'+)) ;> (setf (symbol-function '+) #'cons) ;> (unwind-protect ;> (load "fu") ; note the correct spelling :-) ;> (setf (symbol-function '+) old+)) ;> ; ; ;Unfortunately this solution will not work in a multiprocess ;environment since the global function cell is being set, not bound, ;and all processes will end up using the new definition . What is ;really needed is a way to declare an flet binding special but I don't ;think there is a way to do that. Here is one way. ;; load but don't eval. (defun fake-load (file) (let ((forms '())) (with-open-file (o file :direction :input) (loop (let ((form (read o nil nil))) (if form (push form forms) (return (nreverse forms)))))))) ;; Make sure forms are evaluated in lexical environment of flets. (defmacro load-in-environment (file &rest flets) (let ((forms (fake-load file))) `(flet ,flets (progn ,@forms)))) ;; use it like this: (load-in-environment "foo" ;; contains form (print (+ 1 2)) (+ (a b) (cons a b)) (baz () nil))) ;; return (1 . 2) Propbably one could rewrite this so that it would work compiled, if one really cares. No doubt this will be much slower than LOAD, for reasons that were previously discussed here, and which I forget. --eliot