Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Runtime class definition without eval?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
robert_m_miles  
View profile  
 More options Jan 6 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: robert_m_mi...@yahoo.com
Date: 1999/01/06
Subject: Runtime class definition without eval?
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    


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lyman S. Taylor  
View profile  
 More options Jan 6 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: ly...@cc.gatech.edu (Lyman S. Taylor)
Date: 1999/01/06
Subject: Re: Runtime class definition without eval?
In article <770dr4$1h...@nnrp1.dejanews.com>,

 <robert_m_mi...@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."
(ly...@cc.gatech.edu)         The enhanced EMH Doctor in a ST:Voyager epidsode.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Naggum  
View profile  
 More options Jan 7 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Erik Naggum <e...@naggum.no>
Date: 1999/01/07
Subject: Re: Runtime class definition without eval?
* robert_m_mi...@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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Espen Vestre  
View profile  
 More options Jan 7 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Espen Vestre <e...@nextel.no>
Date: 1999/01/07
Subject: Re: Runtime class definition without eval?

robert_m_mi...@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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »