Re: namespace for class
On Sat, Aug 16, 2008 at 11:37 AM, Sven Emtell <sven@emtell.com> wrote:
> I am translating some MCL code to LispWorks and I found the following:
> In MCL 5.1
> ----------
> Welcome to Macintosh Common Lisp Version 5.1!
> ? (make-package :a)
> #<Package "A">
> ? (in-package a)
> #<Package "A">
> ? (defclass rest () ())
> #<STANDARD-CLASS REST>
> ?
> In LispWorks 5.1.1
> ------------------
> CL-USER 1 > (make-package :a)
> #<The A package, 0/16 internal, 0/16 external>
> CL-USER 2 > (in-package :a)
> #<The A package, 0/16 internal, 0/16 external>
> A 3 > (defclass rest () ())
> Error: Defining class REST visible from package COMMON-LISP.
> 1 (continue) Define it anyway.
> 2 (abort) Return to level 0.
> 3 Return to top loop level 0.
> Type :b for backtrace, :c <option number> to proceed, or :? for other
> options
> A 4 : 1 > *package*
> #<The A package, 1/16 internal, 0/16 external>
> A 5 : 1 >
> So, in MCL I get a class called REST in the package A, while LispWorks won't
> let me have that. I thought that this should work since class names are put
> in the type namespace as opposed to in the function and variable namespaces?
> Why is there a difference between the environments?
> Which environment is doing the right thing?
> What shall I do?
> Please enlighten me!
> /Sven
At first I misunderstood what was going on; I thought that you were
getting the error about a class /re/-definition (and I didn't know of,
and couldn't find, a class called rest.) The error comes about because
the default use list for packages (under Lispworks) includes
COMMON-LISP. That is,
CL-USER 14 > (defpackage "B")
#<The B package, 0/16 internal, 0/16 external>
CL-USER 15 > (package-use-list (find-package "B"))
(#<The COMMON-LISP package, 3/4 internal, 978/1024 external> #<The
HARLEQUIN-COMMON-LISP package, 0/4 internal, 232/256 external> #<The
LISPWORKS package, 58/64 internal, 205/256 external>)
and so, after (in-package "B"), typing (defclass rest () ()) is the
same as (defclass cl:rest () ()), not (defclass b:rest () ()). I'm
only responding because I didn't understand what was going wrong at
first. Others have replied as to why (defclass cl:rest () ()) signals
an error, and what other options you have (shadowing rest, not using
the COMMON-LISP package in your package, doing it anyway, and so on).
Also, it's not a matter of namespaces; that is, it's not that cl:rest
is already defined as a function, otherwise the following would signal
an error, too:
CL-USER 20 > (defclass foobar () ())
#<STANDARD-CLASS FOOBAR 200B9FFF>
CL-USER 21 > (defun foobar ())
FOOBAR
And I think that in MCL, you're not actually getting a class named by
a:rest. I think that if, after you evaluate (in-package :a) and you
try (symbol-package (class-name (find-class 'rest))), you'll see
something like #<The COMMON-LISP package, 3/4 internal, 978/1024
external>.
--
=====================
Joshua Taylor
tayloj@cs.rpi.edu, jtaylor@alum.rpi.edu
"A lot of good things went down one time,
back in the goodle days."
John Hartford