From: Mirko
Subject: package blues: load a file into a package
Date: 
Message-ID: <b33781f8-05a2-4f1c-85f2-3f4c9a640edb@e24g2000vbe.googlegroups.com>
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.

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

From: budden
Subject: Re: package blues: load a file into a package
Date: 
Message-ID: <58e1c4d4-a097-4888-b42a-d535b673495b@p2g2000prn.googlegroups.com>
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
From: Tamas K Papp
Subject: Re: package blues: load a file into a package
Date: 
Message-ID: <6qtcjcFee3boU2@mid.individual.net>
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.

> Any other options?

You could put an (in-package :a) inside B.lisp.

Tamas
From: Rainer Joswig
Subject: Re: package blues: load a file into a package
Date: 
Message-ID: <joswig-D73795.23441917122008@news-europe.giganews.com>
In article 
<····································@e24g2000vbe.googlegroups.com>,
 Mirko <·············@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))

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

-- 
http://lispm.dyndns.org/
From: Tim Bradshaw
Subject: Re: package blues: load a file into a package
Date: 
Message-ID: <ff4d91c3-d5eb-4c16-8e8f-f2aaecc1aceb@b41g2000pra.googlegroups.com>
On Dec 17, 10:19 pm, Mirko <·············@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.
From: budden
Subject: Re: package blues: load a file into a package
Date: 
Message-ID: <d7ad7dbc-ea76-4731-a5e0-daf93f6ff1ed@w39g2000prb.googlegroups.com>
> Bind *PACKAGE* to the right package before doing this.
O-oo-ps. I was wrong :)
From: Mirko
Subject: Re: package blues: load a file into a package
Date: 
Message-ID: <fd6bd2c7-11c6-405c-bb04-f41a1432ed85@b38g2000prf.googlegroups.com>
On Dec 17, 5:19 pm, Mirko <·············@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.
>
> 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.

I will try to dig into the issue later.

Thanks to all the replied,

Mirko
From: budden
Subject: Re: package blues: load a file into a package
Date: 
Message-ID: <70bee8dd-e81c-4524-bada-a625a73a1a62@i24g2000prf.googlegroups.com>
You might also try
(let ((*package* (find-package :a)))
  (load "b"))
This is how I understand Tim Bradshaw's recommendation.