From: Vanna
Subject: newbie question about symbols
Date: 
Message-ID: <8d2qub$b9i$1@lacerta.tiscalinet.it>
Hi,
can anyone help me about this problem ?

I need to compare two symbols defined in different packages, but
functions like eq, eql, equal, an so on, are not suitable to this purpose.

for example
If you try this code

(in-package : package1)
(setf aSymbol 'Mary)

(in-package : package2)

and try this
package2> (eql package1::aSymbol 'Mary)

you will get a NIL

is there any lisp function able to perform this compare?

 thanks in advance
 bye

From: Barry Margolin
Subject: Re: newbie question about symbols
Date: 
Message-ID: <oi6J4.86$my.3204@burlma1-snr2>
In article <············@lacerta.tiscalinet.it>,
Vanna <········@tiscalinet.it> wrote:
>Hi,
>can anyone help me about this problem ?
>
>I need to compare two symbols defined in different packages, but
>functions like eq, eql, equal, an so on, are not suitable to this purpose.
>
>for example
>If you try this code
>
>(in-package : package1)
>(setf aSymbol 'Mary)
>
>(in-package : package2)
>
>and try this
>package2> (eql package1::aSymbol 'Mary)
>
>you will get a NIL
>
>is there any lisp function able to perform this compare?

STRING= will just compare their names.

But if that's all you care about, why are you using symbols rather than
strings in the first place?  If you need to associate data with the
symbols, use a hash table keyed on the strings.

-- 
Barry Margolin, ······@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Coby Beck
Subject: Re: newbie question about symbols
Date: 
Message-ID: <955576976832@NewsSIEVE.cs.bonn.edu>
Vanna <········@tiscalinet.it> wrote in message
·················@lacerta.tiscalinet.it...
| Hi,
| can anyone help me about this problem ?
|
| I need to compare two symbols defined in different packages, but
| functions like eq, eql, equal, an so on, are not suitable to this purpose.
|
| for example
| If you try this code
|
| (in-package : package1)
| (setf aSymbol 'Mary)
|
| (in-package : package2)
|
| and try this
| package2> (eql package1::aSymbol 'Mary)
|
| you will get a NIL
|
| is there any lisp function able to perform this compare?
|

(eql package1::a-symbol 'package1::mary)

this will return t but probably doesn't solve your problem....others will have to tell
you if you can do any better.

I suspect you really need a globally defined constant.

Coby
From: Robert Monfera
Subject: Re: newbie question about symbols
Date: 
Message-ID: <38F4F7E6.AF99E4B8@fisec.com>
Vanna wrote:

> I need to compare two symbols defined in different packages

Based on the examples, you don't want to compare symbols - you want to
compare SYMBOL-NAMEs (hint, hint).  It is rarely necessary, so probably
another way of solving your underlying problem is preferable.

Robert
From: Masoud Pirnazar
Subject: Re: newbie question about symbols
Date: 
Message-ID: <38F504FF.92910FB4@poboxes.com>
Just want to make sure you realize when you do
    package2> (eql package1::aSymbol 'Mary)

the interpreter interns a new symbol 'Mary into package2, so you're
effectively doing
    (eql package1::aSymbol 'package2::Mary)

where the value of package1::aSymbol is the symbol package1::Mary

(So you are asking if two symbols from different packages are the same
symbol).

Vanna wrote:

> Hi,
> can anyone help me about this problem ?
>
> I need to compare two symbols defined in different packages, but
> functions like eq, eql, equal, an so on, are not suitable to this purpose.
>
> for example
> If you try this code
>
> (in-package : package1)
> (setf aSymbol 'Mary)
>
> (in-package : package2)
>
> and try this
> package2> (eql package1::aSymbol 'Mary)
>
> you will get a NIL
>
> is there any lisp function able to perform this compare?
>
>  thanks in advance
>  bye
From: Tim Bradshaw
Subject: Re: newbie question about symbols
Date: 
Message-ID: <ey3itxmvp9n.fsf@cley.com>
* Vanna  wrote:

> I need to compare two symbols defined in different packages, but
> functions like eq, eql, equal, an so on, are not suitable to this purpose.

> for example
> If you try this code

> (in-package : package1)
> (setf aSymbol 'Mary)

> (in-package : package2)

> and try this
package2> (eql package1::aSymbol 'Mary)

> you will get a NIL

I'm not sure what you want to do.  If you want to ask if these symbols
are in fact the same symbol, then what you are doing will tell you
that (and they could be the same symbol).  If you want to know just if
they have the same *name* then you can do something with SYMBOL-NAME
and STRING=.  However, in that case it would almost certainly be
better to just use strings and not spend time circumventing the
package system:

	(setf p1::name "foo")
	(string= "foo" p1::name)

or something.

My guess is you're trying to do something that isn't either of these
-- if you could explain some more we'd probably be able to help
better.

--tim
From: Vanna
Subject: R: newbie question about symbols
Date: 
Message-ID: <8dccb2$pqq$1@pegasus.tiscalinet.it>
Thanks to everyone for the attention,
we will try to explain more clearly what we would like to do:
we deal with a package where are defined some functions that receive some
symbols and compare these symbols with other internal symbols;

we have something like this:

(in-package :package1)


(defparameter *somesymbols* '(FOO1 FOO2 FOO3))


(export '(search-symbol))


(defun search-symbol (aSymbol)
  (find aSymbol *somesymbols* :test #'eql))


Then we call the exported function from another package in this way:

(in-package :mypackage)
(use-package :package1)


(search-symbol 'FOO1)


and get a nil result.

So the issue is to find a way to pass the FOO1 symbol without worrying about
its package to get a T result;
Note that we are unable to change the compare function, in other words we
can't use the string=  function (or something like this) instead of eql in
search-symbol .
A way to solve this problem is to export every symbol FOO1, FOO2, FOO3 from
the package1
but we don't like it because it isn't a general solution.
Another trick would be to change the package of the passed symbol before the
compare but we don't know how it can be done.

We are wondering why it is so difficult to deal with symbols defined in
different packages,
we think that this problem is common to many other Lisp users that want to
take advantage of using different packages.

Kind regards,
Vanna and Carlo


Tim Bradshaw <···@cley.com> wrote in message ···············@cley.com...
> * Vanna  wrote:
>
> > I need to compare two symbols defined in different packages, but
> > functions like eq, eql, equal, an so on, are not suitable to this
purpose.
>
> > for example
> > If you try this code
>
> > (in-package : package1)
> > (setf aSymbol 'Mary)
>
> > (in-package : package2)
>
> > and try this
> package2> (eql package1::aSymbol 'Mary)
>
> > you will get a NIL
>
> I'm not sure what you want to do.  If you want to ask if these symbols
> are in fact the same symbol, then what you are doing will tell you
> that (and they could be the same symbol).  If you want to know just if
> they have the same *name* then you can do something with SYMBOL-NAME
> and STRING=.  However, in that case it would almost certainly be
> better to just use strings and not spend time circumventing the
> package system:
>
> (setf p1::name "foo")
> (string= "foo" p1::name)
>
> or something.
>
> My guess is you're trying to do something that isn't either of these
> -- if you could explain some more we'd probably be able to help
> better.
>
> --tim
>
>
>
From: Tim Bradshaw
Subject: Re: R: newbie question about symbols
Date: 
Message-ID: <ey3aeiu3z20.fsf@cley.com>
* Vanna  wrote:

> We are wondering why it is so difficult to deal with symbols defined in
> different packages,
> we think that this problem is common to many other Lisp users that want to
> take advantage of using different packages.

I think you are misunderstanding what the package system is for.  At a
low level, it's a way of partitioning symbols into different spaces,
and letting you define that some parts of these spaces are shared for
interface purposes.

If you want *all* symbols to be shared, which you seem to (because you
aren't willing to export just the interesting symbols) then you should
have everything in one package.

Another approach would be to export the interesting symbols, which
gives you a defined interface, which would seem like a good idea.  I'm
not sure why you aren't willing to do this: assuming the interesting
symbols are available as the values of variables, it's trivial to map
over them and export them; if it's hard to find what the interesting
symbols are then you have other problems.

A yet other approach would be to use keyword symbols as the keys, this
would probably be the most conventional.

There's nothing wrong with the package system (or rather, there is,
but this isn't it), you're just trying to do something that it wasn't
designed to do (and I don't think it could have been designed to do
it, as what you seem to be trying to do is to have a single namespace
and two namespaces at once).

--tim
From: Vanna
Subject: R: newbie question about symbols
Date: 
Message-ID: <8dccb4$pqq$2@pegasus.tiscalinet.it>
Thanks to everyone for the attention,
we will try to explain more clearly what we would like to do:
we deal with a package where are defined some functions that receive some
symbols and compare these symbols with other internal symbols;

we have something like this:

(in-package :package1)


(defparameter *somesymbols* '(FOO1 FOO2 FOO3))


(export '(search-symbol))


(defun search-symbol (aSymbol)
  (find aSymbol *somesymbols* :test #'eql))


Then we call the exported function from another package in this way:

(in-package :mypackage)
(use-package :package1)


(search-symbol 'FOO1)


and get a nil result.

So the issue is to find a way to pass the FOO1 symbol without worrying about
its package to get a T result;
Note that we are unable to change the compare function, in other words we
can't use the string=  function (or something like this) instead of eql in
search-symbol .
A way to solve this problem is to export every symbol FOO1, FOO2, FOO3 from
the package1
but we don't like it because it isn't a general solution.
Another trick would be to change the package of the passed symbol before the
compare but we don't know how it can be done.

We are wondering why it is so difficult to deal with symbols defined in
different packages,
we think that this problem is common to many other Lisp users that want to
take advantage of using different packages.

Kind regards,
Vanna and Carlo


Tim Bradshaw <···@cley.com> wrote in message ···············@cley.com...
> * Vanna  wrote:
>
> > I need to compare two symbols defined in different packages, but
> > functions like eq, eql, equal, an so on, are not suitable to this
purpose.
>
> > for example
> > If you try this code
>
> > (in-package : package1)
> > (setf aSymbol 'Mary)
>
> > (in-package : package2)
>
> > and try this
> package2> (eql package1::aSymbol 'Mary)
>
> > you will get a NIL
>
> I'm not sure what you want to do.  If you want to ask if these symbols
> are in fact the same symbol, then what you are doing will tell you
> that (and they could be the same symbol).  If you want to know just if
> they have the same *name* then you can do something with SYMBOL-NAME
> and STRING=.  However, in that case it would almost certainly be
> better to just use strings and not spend time circumventing the
> package system:
>
> (setf p1::name "foo")
> (string= "foo" p1::name)
>
> or something.
>
> My guess is you're trying to do something that isn't either of these
> -- if you could explain some more we'd probably be able to help
> better.
>
> --tim
>
>
>
From: Erik Naggum
Subject: Re: R: newbie question about symbols
Date: 
Message-ID: <3164962988991097@naggum.no>
* "Vanna" <········@tiscalinet.it>
| we will try to explain more clearly what we would like to do:
| we deal with a package where are defined some functions that receive some
| symbols and compare these symbols with other internal symbols;

  that's not what you would _like_ to do, it's exactly what you do, and as
  an explanation, it's useless for those who want to help you.  what you
  would like to do is, as a guess, to refer to symbols without a pacakge
  because you have failed to understand the package system.  this is not
  that uncommon, but insisting that the package system is broken is only
  half as common.

  instead of using symbols internal in a given package, use keywords.

| (defparameter *somesymbols* '(FOO1 FOO2 FOO3))

(defparameter *somesymbols* '(:FOO1 :FOO2 :FOO3))

| (search-symbol 'FOO1)

(search-symbol :FOO1)
=> T

| We are wondering why it is so difficult to deal with symbols defined in
| different packages, we think that this problem is common to many other
| Lisp users that want to take advantage of using different packages.

  this arrogance has blocked your progress both in solving the problem and
  in recognizing the difficulties you have experienced.  you have to let go
  of the idea that you're doing something right if it doesn't work, and at
  the very least investigate your options.

#:Erik