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 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.
> Any other options?
You could put an (in-package :a) inside B.lisp.
Tamas
> 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))
RJMBP:tmp joswig$ cmucl
* (load "a.lisp")
; Loading #P"/private/tmp/a.lisp".
;; Loading #P"/private/tmp/b.lisp".
HI-THERE
T
*
>
> 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
(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
> 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 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.
I will try to dig into the issue later.
Thanks to all the replied,
Mirko