David Mittman | 9 Jul 2004 00:15
Picon
Picon

Re: symbold and packages

Defining the p1::goo function like this might help:

(in-package p1)

(defun goo ()
   (p2::test 'p2::p))

Other than that, I'd have to know more about what you see as the 
problem and what you intend these functions to do.

At 5:11 PM -0400 7/8/04, Fabrizio Morbini wrote:
>Hi All, I have the following problem:
>
>-two lisp files, one is in package p1 and the other in package p2. -from
>package user I call (p1::goo). Inside p1::goo it is called a function
>defined in p2 with one argument (lets call this function in p2: fp2).
>-inside fp2 I compare the argument of the function (with the function
>member) with a global variable defined (with defparameter) in p2.
>
>To make the thing more clear this is an example:
>
>******file p1.lisp
>(defpackage p1)
>(defpackage p2)
>(in-package p1)
>
>(defun goo ()
>  (p2::test 'p)
>  )
>
(Continue reading)

Fabrizio Morbini | 9 Jul 2004 00:28
Picon
Favicon

Re: symbold and packages

On Thu, 8 Jul 2004, David Mittman wrote:

> Defining the p1::goo function like this might help:
>
> (in-package p1)
>
> (defun goo ()
>    (p2::test 'p2::p))
>
> Other than that, I'd have to know more about what you see as the
> problem and what you intend these functions to do.

Thanks, I cannot do this because I don't actually pass the symbol p
directly (with 'p) but is read from a file that contains a list of these
symbols and each one of these is passed as parameter to the function.

Basically the package p2 corresponds to a "utilties" package in which I
have a function that adds "a" or "an" before a word as it is the
necessary. The global variable *test* contains a list of words that are
exceptions to the a-or-an rule. So if the current word is a member of
these exceptions than it adds "an" otherwise "a".

Thanks again, Fabrizio.

Ronald Sudomo | 9 Jul 2004 02:17

Re: symbold and packages

Ok. I think now I have a better understanding on what you are trying to 
do. Here is one suggestion:

(let ((*package* (find-package 'p2)))
   (p2::test (read input))
  )

This would make all the symbols read to be in package p2.

--ronald

On Jul 8, 2004, at 4:28 PM, Fabrizio Morbini wrote:

> On Thu, 8 Jul 2004, David Mittman wrote:
>
>> Defining the p1::goo function like this might help:
>>
>> (in-package p1)
>>
>> (defun goo ()
>>    (p2::test 'p2::p))
>>
>> Other than that, I'd have to know more about what you see as the
>> problem and what you intend these functions to do.
>
> Thanks, I cannot do this because I don't actually pass the symbol p
> directly (with 'p) but is read from a file that contains a list of 
> these
> symbols and each one of these is passed as parameter to the function.
>
(Continue reading)

BobGian | 9 Jul 2004 02:14

Re: symbold and packages

> Thanks, I cannot do this because I don't actually pass the symbol p
> directly (with 'p) but is read from a file that contains a list of
> these symbols and each one of these is passed as parameter to the
> function.

Perhaps the problem is that the function which reads the file is in one
package but you want the symbols in the file to read in as being in the
other package.  You can bind *PACKAGE* around the READ to cause the
symbols to read in whatever package you want.  For example:

(in-package "P2")

(with-open-file (strm "input.file" :direction :input)
  (let ((*PACKAGE* (find-package "P1")))
    (setq x (read strm))))

Now file "input.file" contains:

(A B C)

This, when the file is read, will cause the symbol P2::X to become
set to the value (P1::A P1::B P1::C) rather than to the value
(P2::A P2::B P2::C), as would happen if the read happens when the
variable *PACKAGE* is set to the P2 package.

Alternatively, you can put package prefixes on all your symbols in the
file.  Probably the keyword package would be best for that purpose.

Hope that helps.
 -Bob
(Continue reading)

BobGian | 9 Jul 2004 00:38

symbold and packages

> ******file p1.lisp
> (defpackage p1)
> (defpackage p2)
> (in-package p1)
>
> (defun goo ()
>  (p2::fp2 'p)
>  )
>
> ******file p2.lisp
> (in-package p2)
>
> (defparameter *test* '(p q r))
>
> (defun fp2 (x)
>  (print x)
>  (print *test*)
>  (print (member x *test*))
>  )
>
> What I get is:
>
> CL-USER(1): :ld p1.lisp
> ; Loading p1.lisp
> CL-USER(2): :ld p2.lisp
> ; Loading p2.lisp
> CL-USER(3): (p1::goo)
>
> P1::P
> (P2::P P2::Q P2::R)
(Continue reading)

Michael Hannemann | 9 Jul 2004 01:55

Re: symbold and packages

BobGian <at> U.Washington.edu wrote:
>You pass P1::P to P2::FP2 by calling P1::GOO.
>Then P2:FP2 prints P1::P, its argument (OK).
>Then P2:FP2 prints P2::*TEST* (OK).
>Then P2:FP2 prints (member P1::P P2::*TEST*) (which it isn't - OK).
>
>What is wrong?

Presumably he'd like to pretend that packages are irrelevant.  This might 
be a mistake, since, as you say, Lisp is doing what it's supposed to, but 
there are a few options easily available:

1.  Read the symbols in from your file and intern in the "correct" package 
in the process, with something like

   (let ((*read-eval* nil)
       (*package* (find-package the-package)))
     (read-from-string (string-upcase the-string))))

2.  Make sure all the symbols you're reading are in the keyword package, 
e.g. :x :y :z

3.  Add an alternate test to member, like

(member the-symbol the-list :test #'(lambda (x y) (string= (symbol-name x) 
(symbol-name y)))))

Michael

(Continue reading)

Marc LeBrun | 9 Jul 2004 02:08

Re: symbold and packages

 >=Fabrizio Morbini
 > ...I have a function that adds "a" or "an" before a word...

OK, you are basically doing string processing, so symbols aren't really the 
right data type any more than numeric ASCII codes would be.  You ought to 
either do everything with strings in the first place
   (defparameter *test* '("p" "q" "r"))
or, if you must deal with symbols, employ something to "coerce" them to 
strings (as was done implicitly with #'string-equal in my last reply).


Gmane