Path: utzoo!attcan!uunet!cs.utexas.edu!yale!quasi-eli!cs.yale.edu!engelson-sean From: engelson-sean@cs.yale.edu (Wisp Lizard) Newsgroups: comp.lang.lisp Subject: Re: scope/extent interaction with flet and load Message-ID: <1990Oct26.133156@cs.yale.edu> Date: 26 Oct 90 17:31:56 GMT References: <60375@bbn.BBN.COM> Sender: news@cs.yale.edu Reply-To: engelson-sean@cs.yale.edu (Wisp Lizard) Distribution: comp Organization: Yale AI Mobile Robotics Project Lines: 49 Nntp-Posting-Host: argentina.ai.cs.yale.edu In article <60375@bbn.BBN.COM>, sboisen@bbn.com (Sean Boisen) writes: |> |> Scenario: assume a file foo.lisp which contains the following single form. |> |> (print (+ 1 2)) |> |> What i expected to see when executing the following |> |> > (flet ((+ (a b) (cons a b))) (load "foo")) |> |> was something like |> (1 . 2) |> |> Instead (at least under Lucid and Allegro on a Sun) i see |> |> 3 |> |> In other words, my flet "redefinition" of + wasn't in effect when the |> file got loaded, even though it seems to me the loading is inside the |> scope of the flet, according to the rules in CLtL. Can somebody |> explain to me why this behavior is correct (assuming it is)? 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. |> Sean Coincidence? ---------------------------------------------------------------------- Sean Philip Engelson, Poet Errant Make your learning a fixture; Yale Department of Computer Science Say little and do much; Box 2158 Yale Station And receive everyone with New Haven, CT 06520 a friendly attitude. ---------------------------------------------------------------------- For a successful technology, reality must take precedence over public relations, for Nature cannot be fooled. --Richard Feynman