Lisp HUG Maillist Archive

Anonymous class

What are the different ways of handling anonymous class creation and their pros and cons ?
More precisely : you may want to dynamically create classes, but not necessarily name them
nor even keep them. I'm working on a package where such anonymous classes are created
using (ensure-class-using-class nil nil :metaclass some-metaclass)
I fear that defining a class on the nil symbol is not the best choice for portable code.
I'm interested in any comment about this nil/anonymous class thing.

Thanks in advance,
-- 
Fabrice Popineau
-----------------------------
SUPELEC
Département Informatique
3, rue Joliot Curie
91192 Gif/Yvette Cedex
Tel direct : +33 (0) 169851950
Standard : +33 (0) 169851212
------------------------------


Re: Anonymous class



2011/7/10 Bradford W. Miller <bradfordmiller@mac.com>
I'm struggling to understand why you want anonymous classes - are you asking about good design practices in CLOS or are you designing your own programming language using CLOS?

Rather than using nil, why not (gensym)?

I'm trying to port some (quite large) piece of code written using Allegro CL. The guy heavily used this trick, and yes that was the first question I asked myself : why not using gensyms rather than
relying on non portable nil classes ? However I'm not so sure to be able to quickly track down every case of testing for an anonymous class in the code. If I can make it work correctly, then I'll try
to rewrite parts of it.

Mainly, what I was asking on the list was ideas around this nil class definition. Maybe there is some CL trick that I'm not aware of.
Or maybe it is plain wrong to define (and redefine multiple times) a class on nil.

Fabrice 

Re: Anonymous class

If you have legacy code that is trying to define an anonymous class with name NIL, maybe you could add (eql nil) methods for the relevant metafunctions that generate a gensym-ed name.

Paul


----- Original Message -----
From:
"Fabrice Popineau" <fabrice.popineau@supelec.fr>

To:
"Bradford W. Miller" <bradfordmiller@mac.com>
Cc:
"Lispworks HUG" <lisp-hug@lispworks.com>
Sent:
Sun, 10 Jul 2011 17:58:17 +0200
Subject:
Re: Anonymous class




2011/7/10 Bradford W. Miller <bradfordmiller@mac.com>
I'm struggling to understand why you want anonymous classes - are you asking about good design practices in CLOS or are you designing your own programming language using CLOS?

Rather than using nil, why not (gensym)?

I'm trying to port some (quite large) piece of code written using Allegro CL. The guy heavily used this trick, and yes that was the first question I asked myself : why not using gensyms rather than
relying on non portable nil classes ? However I'm not so sure to be able to quickly track down every case of testing for an anonymous class in the code. If I can make it work correctly, then I'll try
to rewrite parts of it.

Mainly, what I was asking on the list was ideas around this nil class definition. Maybe there is some CL trick that I'm not aware of.
Or maybe it is plain wrong to define (and redefine multiple times) a class on nil.

Fabrice 

Re: Anonymous class

Thanks for all the answers, very helpful.
I understand that make-instance is a better way to go than ensure-class-using-class.
I gensym'ed the symbol-name in the mean time.
Once I get this code to work with a reference test case (made much progress this week-end), I'll start rewriting parts of it.
But there are definitely too many interactions in it for me to be confident to do it before.

I'll keep you posted on the progress and eventually success :-)

Best regards,

Fabrice

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