Lisp HUG Maillist Archive

namespace for class

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


Re: namespace for class

On Sat, 16 Aug 2008 17:37:08 +0200, 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!

By 11.1.2.1.2 of the ANSI standard it seems that LispWorks is right.
FWIW, SBCL also complains if you try something like this.  If you
insist on naming the class REST, you should shadow the CL symbol in
your package.

Besides, although not directly related to your problem, you should
note that it is usually better to explicitly specify the packages your
new package should use as the default is implementation-defined and
can thus lead to unportable behaviour.

Also, consider using DEFPACKAGE instead of MAKE-PACKAGE - see the
remark at the end of the MAKE-PACKAGE dictionary entry.

Cheers,
Edi.


Re: namespace for class

This is just some check that LispWorks does to protect some packages 
against redefinition. You can change the value of 
*handle-warn-on-redefinition* to :warn or nil, or you can remove the 
packages you don't want to be warned about from the value of 
*packages-for-warn-on-redefinition*. Or you can just continue with :c 1 
from the error below. See the documentation pages below:

http://www.lispworks.com/documentation/lw51/LWRM/html/lwref-339.htm#11346
http://www.lispworks.com/documentation/lw51/LWRM/html/lwref-227.htm#pgfId-889361

Octav

Sven Emtell 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
>
>


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


Re: namespace for class

On Sat, Aug 16, 2008 at 05:37:08PM +0200, Sven Emtell 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?

To add to the other respondents, perhaps this will also help:

Lispworks:

  CL-USER 3 > (make-package :a :use nil)
  ;                            ^^^^^^^^
  #<The A package, 0/16 internal, 0/16 external>

  CL-USER 4 > (in-package :a)
  #<The A package, 0/16 internal, 0/16 external>

  A 5 > (defclass rest () ())

  Error: Undefined operator DEFCLASS in form (DEFCLASS REST COMMON-LISP:NIL COMMON-LISP:NIL).
    1 (continue) Try invoking DEFCLASS again.
    2 Return some values from the form (DEFCLASS REST COMMON-LISP:NIL COMMON-LISP:NIL).
    3 Try invoking COMMON-LISP:DEFCLASS with the same arguments.
    4 Set the macro-function of DEFCLASS to the macro-function of COMMON-LISP:DEFCLASS.
    5 Try invoking something other than DEFCLASS with the same arguments.
    6 Set the symbol-function of DEFCLASS to another function.
    7 Set the macro-function of DEFCLASS to another function.
    8 (abort) Return to level 0.
    9 Return to top loop level 0.

  Type :b for backtrace, :c <option number> to proceed,  or :? for other options

  A 6 : 1 > :top

  A 7 > (cl:defclass rest () ())
  #<COMMON-LISP:STANDARD-CLASS REST 225CA7A7>

Figuring out why the first "defclass" gave an error may help deepen
your understanding of CL's package system and the CL reader.  Reading
the possible restarts pretty much gives it away, though.  :)

-- L


Updated at: 2020-12-10 08:42 UTC