Ben wrote:Thus, i am not able to put in-package-calls into my code, because i have to use the code in different packages.
I'm not sure of your purpose since you haven't said anything about what your doing
, but this sounds wrong. The only thing I can figure is that you want separate copies of the symbols because you want to mutate these symbols or the data they are associated with. Is this right? I mean are you trying to do something like this:
- Code: Select all
(defun my-func (x) (* 2 x))
(defparameter *a-vector* (vector 1 2 3))
(setf *a-vector* (vector 3 2 1))
==> #(3 2 1)
;; Let's change the definition of PKG2::MY-FUNC
(defun my-func (x) (* 3 x))
==> #(1 2 3)
;; PKG1::MY-FUNC still has the same definition
;; PKG1::*A-VECTOR* still has the changed value
==> #(3 2 1)
I can definitely understand how you would desire to do this in the case where you have a closure as a top level form; you would need two independent copies of these closures or they may interfere with each other.
If this is the sort of thing you want, I think you should be creating these symbols via a function call (a function that is defined in file1.lisp), not by loading file1.lisp and having LOAD do your dirty work for you. It is hard to write an example when I don't have something to work from, but if I wanted to have multiple instances of some data, I would provide a function that either returns newly allocated data or takes symbols and defines sets newly allocated data to those symbols. I.e. instead of using (load #p"file1") to get a copy of all of the symbols you want, I would have a function like (init-file1-environment ... some args...) that returns or defines the proper environment for whatever work you want to do. In addition, if make your function just returns the proper objects, you are most of the way to providing a WITH-FILE1-ENVIRONMENT macro.