Path: utzoo!attcan!uunet!cs.utexas.edu!hellgate.utah.edu!cdr.utah.edu!moore From: moore%cdr.utah.edu@cs.utah.edu (Tim Moore) Newsgroups: comp.lang.lisp Subject: Re: scope/extent interaction with flet and load Message-ID: <1990Oct26.122108.27095@hellgate.utah.edu> Date: 26 Oct 90 18:21:08 GMT References: <60375@bbn.BBN.COM> <1990Oct26.133156@cs.yale.edu> Distribution: comp Organization: University of Utah CS Dept Lines: 39 In article <1990Oct26.133156@cs.yale.edu> engelson-sean@cs.yale.edu (Wisp Lizard) writes: >In article <60375@bbn.BBN.COM>, sboisen@bbn.com (Sean Boisen) writes: >|> >|>[rebinding macros and functions doesn't work as expected when loading] > >This behavior is correct because of Common Lisp's lexical scoping; the >contents of the file are outside the lexical scope of the flet. 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+)) > >Note the use of unwind-protect in case an error occurs while loading. I >don't know how to do this with macros, however. I'm sure the function names are for illustrative purposes, but remember that redefining CL functions like #'+ is a really bad idea. You can do the same trick with macros: (let ((old-macro-def (macro-function 'foo))) (setf (macro-function 'foo) (macro-function 'bar)) (unwind-protect (load "foo") (setf (macro-function 'foo) old-macro-def))) With the new macro functions in CLtL2 it's not hard to write a macro that dynamically binds macro definitions. Of course, this only will only work for forms that are being explicitly evaluated (either by eval or load). >|> Sean Tim Moore moore@cs.utah.edu {bellcore,hplabs}!utah-cs!moore "Ah, youth. Ah, statute of limitations." -John Waters