[Ecls-list] Weird behavior with package variable named "STRING"

Larry Clapp larry at theclapp.org
Thu Dec 1 08:08:03 UTC 2005


On Thu, Dec 01, 2005 at 04:15:58PM +0100, Goffioul Michael wrote:
> Here's a piece of ECL session:
> 
> > (defpackage "A")
> #<"A" package>
> > (defpackage "B")
> #<"B" package>
> > (defvar a::string 261)
> STRING
> > (defvar b::string 262)
> STRING
> > a::string
> 261
> > b::string
> 261
> 
> As you can see, the "STRING" variable in package "B" has not the
> expected value. Is this normal? This does not happen with another
> variable name (I tried with "num" instead of "string").

The same thing happens in CMUCL, which makes me think it's supposed to
happen that way.

The COMMON-LISP package exports the STRING symbol, and DEFPACKAGE
probably :USEes COMMON-LISP unless you say otherwise (the Hyperspec
says the default USE list is implementation defined; I can't find the
default for CMUCL; I haven't checked for ECL), in which case a::string
and b::string are the same symbol.  E.g., notice that when you
DEFVAR'd a::string, it returned STRING, not A::STRING.

A bit of experimentation (in ECL, not CMUCL) confirms this:

> (defpackage :a (:use))
#<"A" package>
> (defpackage :b (:use))
#<"B" package>
> (defvar a::string 'a)
A::STRING
> (defvar b::string 'b)
B::STRING
> a::string
A
> b::string
B
> 'a::string
A::STRING
> 'b::string
B::STRING

> (defpackage :c)
#<"C" package>
> (defvar string 'foo)	; note: not C::STRING, just STRING
STRING
> c::string
FOO			; C::STRING and STRING are the same symbol
> 'c::string
STRING
> 'string
STRING

> (package-use-list :a)
NIL
> (package-use-list :c)
(#<"COMMON-LISP" package>)

-- Larry





More information about the ecl-devel mailing list