I have a package A. I would like to load a file B.lisp that has no package definitions. However when (in-package :A), B's symbols are invisible. They are in :cl-user.
I tried putting (load #P/"/path-to-B/B") inside A.lisp thinking (I mean hoping) that this would include B's symbols into package A, but that did not work.
I could define a package B, export its symbols and import them into A, but it is an overkill for the small file B. In addition, B is a source file generated by Andrew Smith (state machine), and I don't want to change it.
I could keep A without its package (keep it in cl-user), but it depends on other packages, and I do not know how to import the `public' symbols from those other packages into cl-user.
On Wed, 17 Dec 2008 14:19:38 -0800, Mirko wrote: > I tried putting (load #P/"/path-to-B/B") inside A.lisp thinking (I mean > hoping) that this would include B's symbols into package A, but that did > not work.
But I think it should, unless you do something to *package* inside B.lisp.
In article <b33781f8-05a2-4f1c-85f2-3f4c9a640...@e24g2000vbe.googlegroups.com>,
Mirko <Mirko.Vuko...@gmail.com> wrote: > Here is the story:
> I have a package A. I would like to load a file B.lisp that has no > package definitions. However when (in-package :A), B's symbols are > invisible. They are in :cl-user.
If they are in CL-USER, then *package* really is CL-USER when you load that package.
> I tried putting (load #P/"/path-to-B/B") inside A.lisp thinking (I > mean hoping) that this would include B's symbols into package A, but > that did not work.
What exactly did you do? When compile file a and it has a load statement, nothing happens. You have to tell the compiler that it should load it (using EVAL-WHEN).
Anyway a simple example with load:
RJMBP:tmp joswig$ cat a.lisp (defpackage "A" (:use "CL"))
(in-package "A")
(load "b.lisp")
(b)
RJMBP:tmp joswig$ cat b.lisp (defun b () (print 'hi-there))
> I could define a package B, export its symbols and import them into A, > but it is an overkill for the small file B. In addition, B is a > source file generated by Andrew Smith (state machine), and I don't > want to change it.
> I could keep A without its package (keep it in cl-user), but it > depends on other packages, and I do not know how to import the > `public' symbols from those other packages into cl-user.
Yeah, the best solution is to put (in-package :a) to b.lisp. Yes, I know you can't. Really? 1. You can read Andrew Smith manual. If it is a good tool, it should be able to issue defpackage form. Maybe some configuration option help. 2. If not, you might patch codegenerator itself. 3. If not, just make new file b.tmp.lisp from b.lisp, where (in- package :a) is prepended to b.lisp contents and load b.tmp.lisp instead. 4. After all, you can define your own version of load. Simplest thing is like this:
(defun my-load (file-name) (let ((*package* (find-package :iterate))) (with-open-file (in file-name) (loop for s = (read in nil nil) unless s do (loop-finish) do (eval s)))))
Note you lose ability to compile here. If you want better solution, set up slime, sbcl/ccl and navigate through implementation sources - you'll be able to borrow code from there.
-------------------------------------------------------------- Budden, $5/hour lisp freelancer. Hire me until it is too late
On Dec 17, 10:19 pm, Mirko <Mirko.Vuko...@gmail.com> wrote:
> I tried putting (load #P/"/path-to-B/B") inside A.lisp thinking (I > mean hoping) that this would include B's symbols into package A, but > that did not work.
Bind *PACKAGE* to the right package before doing this.
> I have a package A. I would like to load a file B.lisp that has no > package definitions. However when (in-package :A), B's symbols are > invisible. They are in :cl-user.
> I tried putting (load #P/"/path-to-B/B") inside A.lisp thinking (I > mean hoping) that this would include B's symbols into package A, but > that did not work.
> I could define a package B, export its symbols and import them into A, > but it is an overkill for the small file B. In addition, B is a > source file generated by Andrew Smith (state machine), and I don't > want to change it.
> I could keep A without its package (keep it in cl-user), but it > depends on other packages, and I do not know how to import the > `public' symbols from those other packages into cl-user.
> Any other options?
> Thank you,
> Mirko
I tried Rainer's simple example and it does work. The loaded file is in the package of the parent (hyperspec says the same thing).
But in my case I am still having trouble. Evidently my problem lies somewhere else. For now, I did the `dirty' thing, and inserted a (in- package ...) statement in the loaded file.