From: ············@gmail.com
Subject: exporting a symbol and name conflicts
Date: 
Message-ID: <6d974697-83a4-49e7-bdcd-24945643d80b@m73g2000hsh.googlegroups.com>
hello,

I want to export symbols from the default package.

CL-USER> (defvar *foo* nil)
*FOO*
CL-USER> (export '*foo* :cl-user)
T
CL-USER> (defpackage :bar (:use :cl :cl-user))
#<PACKAGE "BAR">
CL-USER> (in-package :bar)
#<PACKAGE "BAR">
BAR> (boundp '*foo*)
T
BAR> (symbol-package '*foo*)
#<PACKAGE "COMMON-LISP-USER">
BAR>

But if i define/enter another package before, and check if the symbol
is bounded, an export call leads  to a name conflict (and I land into
the debugger):

CL-USER> (defvar *foo* nil)
*FOO*
CL-USER> (defpackage :bar (:use :cl :cl-user))
#<PACKAGE "BAR">
CL-USER> (in-package :bar)
#<PACKAGE "BAR">
BAR> (boundp '*foo*)
NIL
BAR> (in-package :cl-user)
#<PACKAGE "COMMON-LISP-USER">
CL-USER> (export '*foo* :cl-user)
-:**  *slime-repl sbcl*
EXPORT *FOO* causes name-conflicts in #<PACKAGE "BAR"> between the
following
symbols:
  *FOO*, BAR::*FOO*
   [Condition of type SB-INT:NAME-CONFLICT]

It's look like the boundp has a hudge side-effect by creating the
symbol in the :bar package.
How to safely export a given symbol from the current *package* ?

-Nicolas
From: Pascal J. Bourguignon
Subject: Re: exporting a symbol and name conflicts
Date: 
Message-ID: <7ciqvraxuf.fsf@pbourguignon.anevia.com>
············@gmail.com writes:

> hello,
>
> I want to export symbols from the default package.
>
> CL-USER> (defvar *foo* nil)
> *FOO*
> CL-USER> (export '*foo* :cl-user)
> T
> CL-USER> (defpackage :bar (:use :cl :cl-user))
> #<PACKAGE "BAR">
> CL-USER> (in-package :bar)
> #<PACKAGE "BAR">
> BAR> (boundp '*foo*)
> T
> BAR> (symbol-package '*foo*)
> #<PACKAGE "COMMON-LISP-USER">
> BAR>
>
> But if i define/enter another package before, and check if the symbol
> is bounded, an export call leads  to a name conflict (and I land into
> the debugger):
>
> CL-USER> (defvar *foo* nil)
> *FOO*
> CL-USER> (defpackage :bar (:use :cl :cl-user))
> #<PACKAGE "BAR">
> CL-USER> (in-package :bar)
> #<PACKAGE "BAR">
> BAR> (boundp '*foo*)
> NIL
> BAR> (in-package :cl-user)
> #<PACKAGE "COMMON-LISP-USER">
> CL-USER> (export '*foo* :cl-user)
> -:**  *slime-repl sbcl*
> EXPORT *FOO* causes name-conflicts in #<PACKAGE "BAR"> between the
> following
> symbols:
>   *FOO*, BAR::*FOO*
>    [Condition of type SB-INT:NAME-CONFLICT]
>
> It's look like the boundp has a hudge side-effect by creating the
> symbol in the :bar package.
> How to safely export a given symbol from the current *package* ?

This is not BOUNDP, but the lisp reader, who will INTERN the symbol
you type in.

If you don't want to intern the symbol, you have to avoid reading it.

You can still test whether there is a symbol with such a name in the
current package, and if so, if it's BOUNDP:

(defun exists-and-boundp (symbol-name &optional (package *package*))
   (multiple-value-bind (sym there) (find-symbol symbol-name package)
      (and there (boundp sym))))


Otherwise, the current behavior is very safe, FSVO "safe".
If you could precise what you want, we could propose solutions.


Perhaps the most simple thing to do be to never "inherit" symbols
(never :USE a package).  Then EXPORT would never cause a conflict.
But you would have to qualify all the external symbols:
CL-USER:*FOO*

Note that if you try to use a new symbol, or not exported yet:
CL-USER:*BAR* you might get an error, but at least *BAR* will be
interned in the right package, and a later (in-package :cl-user)
(export '*bar* :cl-user) will work as you want.


-- 
__Pascal Bourguignon__