From: ··············@yahoo.com
Subject: Runtime class definition without eval?
Date: 
Message-ID: <770dr4$1hh$1@nnrp1.dejanews.com>
Is this possible? Say I want my code to take the name `human' from the user
and create a new class named human. I could do

(eval (list 'defclass user-input inheritance slots-list))

which could then be

(eval (defclass human () ((name :accessor name))))

But there probably is a way to get the first arg of defclass to evaluate to a
form or symbol without using eval, right?

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    

From: Lyman S. Taylor
Subject: Re: Runtime class definition without eval?
Date: 
Message-ID: <770hta$3jp@pravda.cc.gatech.edu>
In article <············@nnrp1.dejanews.com>,
 <··············@yahoo.com> wrote:
>Is this possible? Say I want my code to take the name `human' from the user
>and create a new class named human. I could do
>
>But there probably is a way to get the first arg of defclass to evaluate to a
>form or symbol without using eval, right?

   Since DEFCLASS is a macro.... no.   DEFCLASS doesn't evaluate the 
   first argument. So you will need to "eval" the whole statement. 
   
   By the way....  backquote is useful in this context.

USER(13): (eval `(defclass ,(read) () ((name :accessor name))) )
human
#<STANDARD-CLASS HUMAN>
USER(14):  (describe 'human )
HUMAN is a SYMBOL.
  It is unbound.
  It is INTERNAL in the COMMON-LISP-USER package.
  It names a class #<STANDARD-CLASS HUMAN>
USER(15): 


   P.S.   If you lisp implementation has a directway of creating 
           classess then you wouldn't need eval.  Something along he 
           lines of 
             (progn 
                 ....  pre creation magic ... 
                (make-instance 'standard-class ... some magic ... ) 
                 .... post creation magic ... )

           There may be a MOP way of doing creating a new class... but I 
           can't remember at the moment. As much as I like to discourage 
           use of eval, it works in this context. ;-) 
           [ It isn't necessary, but it is the quick, portable solution. ]
-- 

Lyman S. Taylor            "I'm a Doctor! Not a commando." 
(·····@cc.gatech.edu)         The enhanced EMH Doctor in a ST:Voyager epidsode.
From: Erik Naggum
Subject: Re: Runtime class definition without eval?
Date: 
Message-ID: <3124683401841045@naggum.no>
* ··············@yahoo.com
| Is this possible? Say I want my code to take the name `human' from the user
| and create a new class named human. I could do
| 
| (eval (list 'defclass user-input inheritance slots-list))
| 
| which could then be
| 
| (eval (defclass human () ((name :accessor name))))
| 
| But there probably is a way to get the first arg of defclass to evaluate
| to a form or symbol without using eval, right?

  consider MACROEXPAND and see what DEFCLASS expands into.  it should be
  instructive.

#:Erik
From: Espen Vestre
Subject: Re: Runtime class definition without eval?
Date: 
Message-ID: <w6yanfs7tw.fsf@gromit.nextel.no>
··············@yahoo.com writes:

> Is this possible? Say I want my code to take the name `human' from the user
> and create a new class named human. I could do

If you're using a lisp which implements the MOP, see the documentation
of ensure-class.  Otherwise, follow Erik's advice and see what defclass
expands into (which probably will be internal to some system-defined
package, i.e. something you shouldn't be messing with without taking
appropriate care).

-- 

  regards,
    Espen Vestre  -- Telenor Nextel AS -- Norway