From: mark carroll
Subject: Run-time type generation
Date: 
Message-ID: <586rlnINN6f1@maine.cis.ohio-state.edu>
I'm new to Lisp, being more used to languages like ML and
Modula-3. I've heard that Common Lisp offers an interesting type
system whereby a program can generate new datatypes at runtime,
etc. This intrigues me a lot: I've never seen anything quite like it,
so I'd be very grateful if anyone could provide a brief example to
show me how this sort of thing is done and used in Common Lisp. (-:

In anticipation...

-- Mark
From: Peter Denno
Subject: Re: Run-time type generation
Date: 
Message-ID: <32D1213E.41C67EA6@cme.nist.gov>
mark carroll wrote:
> 
> I'm new to Lisp, being more used to languages like ML and
> Modula-3. I've heard that Common Lisp offers an interesting type
> system whereby a program can generate new datatypes at runtime,
> etc. This intrigues me a lot: I've never seen anything quite like it,
> so I'd be very grateful if anyone could provide a brief example to
> show me how this sort of thing is done and used in Common Lisp. (-:
> 
> In anticipation...
> 


This is one of the nicest capabilities of Lisp. It is why lisp is 
called a dynamic oo language. There really isn't any special trick
to making it happen. You tend to take it for granted after a while.
A simple way to accomplish it (with CLOS classes) is to load
a class definition into the running lisp. 

(defclass my-class () ((my-slot :accessor my-slot)))

Write it to a file, load it and use it. 

Of course, there are more elementary ways, that do not
require writing to a file. Doing in your program whatever
defclass does, which you can see by typing:
(macroexpand-1 '(defclass my-class...
will give you some ideas. 

If it CLOS classes you are interested in generating
you might want to look at the book "The Art of the
Metaobject Protocol" by Gregor Kiczales et. al.  

If you want to see how I used this kind of stuff to great
benefit you can check out the paper:
"Dynamic Objects and Meta-level Programming of an EXPRESS Language
Environment" at http://www.nist.gov/msidstaff/denno.htm

I can send you the entire code if you really want to see this
in detail. 

-- 
Best regards,
Peter