From: ···········@gmail.com
Subject: Package system question
Date: 
Message-ID: <1112371655.313594.224390@f14g2000cwb.googlegroups.com>
So I have a function:

(in-package :yahoo)

(defun fetch-xml (query format start results)
  "fetch the yahoo XML sheet"
  (let ((*package* (find-package :yahoo))) ;xmlreader must be in
package :yahoo
    (read query)))

Such that the 'read' needs to be executed in the context of the yahoo
package (because when using xmlisp, the reader only looks for xml
objects in the current package, which makes sense).   Is rebinding the
*package* variable (since its dynamic) the best way to go, or is there
something else I'm missing?   Just looking for a best-practice sort of
answer.

Thanks!
-Dave watson
········@docwatson.org

From: ···········@gmail.com
Subject: Re: Package system question
Date: 
Message-ID: <1112372555.909610.117170@l41g2000cwc.googlegroups.com>
Also, is there a way to remove the duplicated :yahoo package names?
It would be bad to change one and forget the other...
From: Mario S. Mommer
Subject: Re: Package system question
Date: 
Message-ID: <ymif4qeq5tlw.fsf@droog.sdf-eu.org>
···········@gmail.com writes:
> Also, is there a way to remove the duplicated :yahoo package names?
> It would be bad to change one and forget the other...

use *package*. It always contains the current package.
From: Peter Seibel
Subject: Re: Package system question
Date: 
Message-ID: <m3oecyflis.fsf@gigamonkeys.com>
Mario S. Mommer <········@yahoo.com> writes:

> ···········@gmail.com writes:
>> Also, is there a way to remove the duplicated :yahoo package names?
>> It would be bad to change one and forget the other...
>
> use *package*. It always contains the current package.

But isn't the problem that he doesn't know what the value of *PACKAGE*
will be when his function is called?

-Peter

-- 
Peter Seibel                                     ·····@gigamonkeys.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp
From: Mario S. Mommer
Subject: Re: Package system question
Date: 
Message-ID: <ymifpsxep7e3.fsf@droog.sdf-eu.org>
Peter Seibel <·····@gigamonkeys.com> writes:
> Mario S. Mommer <········@yahoo.com> writes:
> > ···········@gmail.com writes:
> >> Also, is there a way to remove the duplicated :yahoo package names?
> >> It would be bad to change one and forget the other...
> >
> > use *package*. It always contains the current package.
> 
> But isn't the problem that he doesn't know what the value of *PACKAGE*
> will be when his function is called?

Indeed!

Well, I suppose that

(let ((this-package *package*))
   (defun dafunction  ...))

does the trick then. Inside of dafunction, this-package will always
have the package where the function was defined. Or am I missing
something?
From: Pascal Bourguignon
Subject: Re: Package system question
Date: 
Message-ID: <87hdiqqts8.fsf@thalassa.informatimago.com>
Mario S. Mommer <········@yahoo.com> writes:

> ···········@gmail.com writes:
> > Also, is there a way to remove the duplicated :yahoo package names?
> > It would be bad to change one and forget the other...
> 
> use *package*. It always contains the current package.

_At_ _run_ _time_ !

(defpackage "YAHOO" (:use "COMMON-LISP"))
(in-package "YAHOO")
(defun f () (print *package*))
(f)
(in-package "COMMON-LISP-USER")
(yahoo::f)


Prints:
#<PACKAGE YAHOO> 
#<PACKAGE COMMON-LISP-USER> 

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

Nobody can fix the economy.  Nobody can be trusted with their finger
on the button.  Nobody's perfect.  VOTE FOR NOBODY.
From: Sam Steingold
Subject: Re: Package system question
Date: 
Message-ID: <uis365ovr.fsf@gnu.org>
> *  <···········@tznvy.pbz> [2005-04-01 08:07:35 -0800]:
>
> So I have a function:
>
> (in-package :yahoo)
>
> (defun fetch-xml (query format start results)
>   "fetch the yahoo XML sheet"
>   (let ((*package* (find-package :yahoo))) ;xmlreader must be in
> package :yahoo
>     (read query)))
>
> Such that the 'read' needs to be executed in the context of the yahoo
> package (because when using xmlisp, the reader only looks for xml
> objects in the current package, which makes sense).   Is rebinding the
> *package* variable (since its dynamic) the best way to go, or is there
> something else I'm missing?   Just looking for a best-practice sort of
> answer.

(in-package :yahoo)
(defun fetch-xml (query format start results)
  "fetch the yahoo XML sheet"
  (let ((*package* #.*package*))
    (read query)))


-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.openvotingconsortium.org/> <http://www.dhimmi.com/>
<http://www.iris.org.il> <http://www.memri.org/> <http://www.camera.org>
C combines the power of assembler with the portability of assembler.
From: Harald Hanche-Olsen
Subject: Re: Package system question
Date: 
Message-ID: <pcoacoitgcl.fsf@shuttle.math.ntnu.no>
+ Sam Steingold <···@gnu.org>:

| (in-package :yahoo)
| (defun fetch-xml (query format start results)
|   "fetch the yahoo XML sheet"
|   (let ((*package* #.*package*))
|     (read query)))

Will that work right in a compiled file, though?  I suspect not.
Should that be

    (let ((*package* (find-package #.(package-name *package*)))) ...)

instead?

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- Debating gives most of us much more psychological satisfaction
  than thinking does: but it deprives us of whatever chance there is
  of getting closer to the truth.  -- C.P. Snow
From: Christophe Rhodes
Subject: Re: Package system question
Date: 
Message-ID: <sq3bua1bv7.fsf@cam.ac.uk>
Harald Hanche-Olsen <······@math.ntnu.no> writes:

> + Sam Steingold <···@gnu.org>:
>
> | (in-package :yahoo)
> | (defun fetch-xml (query format start results)
> |   "fetch the yahoo XML sheet"
> |   (let ((*package* #.*package*))
> |     (read query)))
>
> Will that work right in a compiled file, though?  I suspect not.

You suspect wrongly.  Defined similarity.  3.2.4.2.2

Christophe
From: Harald Hanche-Olsen
Subject: Re: Package system question
Date: 
Message-ID: <pcoy8c2rusz.fsf@shuttle.math.ntnu.no>
+ Christophe Rhodes <·····@cam.ac.uk>:

| Harald Hanche-Olsen <······@math.ntnu.no> writes:
| 
| > + Sam Steingold <···@gnu.org>:
| >
| > | (in-package :yahoo)
| > | (defun fetch-xml (query format start results)
| > |   "fetch the yahoo XML sheet"
| > |   (let ((*package* #.*package*))
| > |     (read query)))
| >
| > Will that work right in a compiled file, though?  I suspect not.
| 
| You suspect wrongly.  Defined similarity.  3.2.4.2.2

Woohoo.  My first reaction was, this is silly, why make such a strange
special case out of something no reasonable person would expect to
work in the first place anyway?  (And if so, you wouldn't even think
to look it up to find out if it is so, just as I didn't bother to look
it up before posting.

But then I realized that this is in fact useful behaviour, because you
need to be able to externalize symbols, and since symbols reference
their home package, there you go - you might as well make this special
rule for consistency's sake, even though I suppose it isn't logically
necessary.  That this enables you to do the above trick comes perhaps
more as an accidental side effect than as a raison d'�tre (pardon my
French) for this rule.  Sorry if this is just so much noise, but I
find it easier in internalizing what seems at first like arbitrary
rules when can figure out how they all connect and make sense.

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- Debating gives most of us much more psychological satisfaction
  than thinking does: but it deprives us of whatever chance there is
  of getting closer to the truth.  -- C.P. Snow
From: Pascal Bourguignon
Subject: Re: Package system question
Date: 
Message-ID: <87d5teqtks.fsf@thalassa.informatimago.com>
···········@gmail.com writes:

> So I have a function:
> 
> (in-package :yahoo)
> 
> (defun fetch-xml (query format start results)
>   "fetch the yahoo XML sheet"
>   (let ((*package* (find-package :yahoo))) ;xmlreader must be in
> package :yahoo
>     (read query)))
> 
> Such that the 'read' needs to be executed in the context of the yahoo
> package (because when using xmlisp, the reader only looks for xml
> objects in the current package, which makes sense).   Is rebinding the
> *package* variable (since its dynamic) the best way to go, or is there
> something else I'm missing?   Just looking for a best-practice sort of
> answer.

It's good practice.



> Also, is there a way to remove the duplicated :yahoo package names?
> It would be bad to change one and forget the other...

Lisp is a first-class language. You can use a variable everywhere,
just use a macro or EVAL (bad!)...


(defconstant yahoo-package :yahoo)
(eval `(in-package ,yahoo-package))
(defun fetch-xml (query format start results)
   "fetch the yahoo XML sheet"
   (let ((*package* (find-package yahoo-package))) ; xmlreader must be in
                                                   ; package :yahoo
     (read query)))

So, now we have yahoo-package thrice instead of :yahoo twice.
Anybody can help?

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

Nobody can fix the economy.  Nobody can be trusted with their finger
on the button.  Nobody's perfect.  VOTE FOR NOBODY.
From: Alexander Repenning
Subject: Re: Package system question
Date: 
Message-ID: <1112460490.396547.99140@f14g2000cwb.googlegroups.com>
···········@gmail.com wrote:

> Such that the 'read' needs to be executed in the context of the yahoo
> package (because when using xmlisp, the reader only looks for xml
> objects in the current package, which makes sense).   Is rebinding
the
> *package* variable (since its dynamic) the best way to go, or is
there
> something else I'm missing?   Just looking for a best-practice sort
of
> answer.

Makes perfect sense. Since most people want this kind of control we
added a short while ago a package parameter to load-object of XMLisp
(2.1.3 which needs to be uploaded):

(defun LOAD-OBJECT (Filename &key Verbose (If-Does-Not-Exist :error)
(Package *Package*)) "
  in: Filename pathname;
    &key Verbose boolean;
    if-does-not-exist action default :error;
   package package default *Package*.
 out: Object t.
 Load XML object contained in <Filename> into package and return it."
  (when Verbose (format t ";; loading object in file: ~A~%" Filename))
  (let ((*Package* Package))
    (with-open-file (File Filename :direction :input :if-does-not-exist
If-Does-Not-Exist)
      (read File))))
From: Alexander Repenning
Subject: Re: Package system question
Date: 
Message-ID: <1112460592.950348.85890@g14g2000cwa.googlegroups.com>
···········@gmail.com wrote:

> Such that the 'read' needs to be executed in the context of the yahoo
> package (because when using xmlisp, the reader only looks for xml
> objects in the current package, which makes sense).   Is rebinding
the
> *package* variable (since its dynamic) the best way to go, or is
there
> something else I'm missing?   Just looking for a best-practice sort
of
> answer.

Makes perfect sense. Since most people want this kind of control we
added a short while ago a package parameter to load-object of XMLisp
(2.1.3 which needs to be uploaded):

(defun LOAD-OBJECT (Filename &key Verbose (If-Does-Not-Exist :error)
(Package *Package*)) "
  in: Filename pathname;
    &key Verbose boolean;
    if-does-not-exist action default :error;
   package package default *Package*.
 out: Object t.
 Load XML object contained in <Filename> into package and return it."
  (when Verbose (format t ";; loading object in file: ~A~%" Filename))
  (let ((*Package* Package))
    (with-open-file (File Filename :direction :input :if-does-not-exist
If-Does-Not-Exist)
      (read File))))
From: Alexander Repenning
Subject: Re: Package system question
Date: 
Message-ID: <1112460712.102852.169220@z14g2000cwz.googlegroups.com>
···········@gmail.com wrote:

> Such that the 'read' needs to be executed in the context of the yahoo
> package (because when using xmlisp, the reader only looks for xml
> objects in the current package, which makes sense).   Is rebinding
the
> *package* variable (since its dynamic) the best way to go, or is
there
> something else I'm missing?   Just looking for a best-practice sort
of
> answer.

Makes perfect sense. Since most people want this kind of control we
added a short while ago a package parameter to load-object of XMLisp
(2.1.3 which needs to be uploaded):

(defun LOAD-OBJECT (Filename &key Verbose (If-Does-Not-Exist :error)
(Package *Package*)) "
  in: Filename pathname;
    &key Verbose boolean;
    if-does-not-exist action default :error;
   package package default *Package*.
 out: Object t.
 Load XML object contained in <Filename> into package and return it."
  (when Verbose (format t ";; loading object in file: ~A~%" Filename))
  (let ((*Package* Package))
    (with-open-file (File Filename :direction :input :if-does-not-exist
If-Does-Not-Exist)
      (read File))))
From: Alexander Repenning
Subject: Re: Package system question
Date: 
Message-ID: <1112460831.605875.324210@o13g2000cwo.googlegroups.com>
···········@gmail.com wrote:

> Such that the 'read' needs to be executed in the context of the yahoo
> package (because when using xmlisp, the reader only looks for xml
> objects in the current package, which makes sense).   Is rebinding
the
> *package* variable (since its dynamic) the best way to go, or is
there
> something else I'm missing?   Just looking for a best-practice sort
of
> answer.

Makes perfect sense. Since most people want this kind of control we
added a short while ago a package parameter to load-object of XMLisp
(2.1.3 which needs to be uploaded):

(defun LOAD-OBJECT (Filename &key Verbose (If-Does-Not-Exist :error)
(Package *Package*)) "
  in: Filename pathname;
    &key Verbose boolean;
    if-does-not-exist action default :error;
   package package default *Package*.
 out: Object t.
 Load XML object contained in <Filename> into package and return it."
  (when Verbose (format t ";; loading object in file: ~A~%" Filename))
  (let ((*Package* Package))
    (with-open-file (File Filename :direction :input :if-does-not-exist
If-Does-Not-Exist)
      (read File))))