Re: make-instance without initialize-instance
- From: "Captain Obvious" <udodenko@xxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 13 May 2010 21:15:33 +0300
TKP> I think that I have to call allocate-instance, but when I try
TKP> (allocate-instance (find-class 'my-class))
TKP> I get an error condition (which SBCL is "unable to display", so I must
TKP> have screwed up heavily). What's the proper way to do what I want?
Well, allocate-instance itself works fine:
CL-USER> (defclass test1 () (a))
#<STANDARD-CLASS TEST1>
CL-USER> (allocate-instance (find-class 'test1))
#<TEST1 {C5C9AA1}>
If it doesn't work with your class, it is some problem you have in your code.
E.g. one way to implement this error:
CL-USER> (defmethod print-object ((o test1) stream)
(format stream "#<TEST1 a=~a>" (slot-value o 'a)))
CL-USER> (allocate-instance (find-class 'test1))
Unable to display error condition
[Condition of type UNBOUND-SLOT]
0: ((SB-PCL::FAST-METHOD SLOT-UNBOUND (T T T)) #<error printing object>)
1: (SB-PCL::SLOT-UNBOUND-INTERNAL #<error printing object>)
2: ((SB-PCL::FAST-METHOD PRINT-OBJECT
(TEST1 T)) #<error printing object>)
3: (SB-PRETTY:OUTPUT-PRETTY-OBJECT #<error printing object>)
4: (SB-IMPL::STRINGIFY-OBJECT #<error printing object>)
5: (PRIN1-TO-STRING #<error printing object>)
That is, forget to initialize a slot and write a print-object which uses that slot, and you'll get "Unable to display" thing.
By the way, you might want to use shared-initialize (it is more flexible than initialize-instance) after allocate-instance, but it is not strictly necessary, depends on your goal.
.
- Follow-Ups:
- Re: make-instance without initialize-instance
- From: Tamas K Papp
- Re: make-instance without initialize-instance
- References:
- make-instance without initialize-instance
- From: Tamas K Papp
- make-instance without initialize-instance
- Prev by Date: Re: ECL 10.4.1
- Next by Date: Re: HTML Library
- Previous by thread: Re: make-instance without initialize-instance
- Next by thread: Re: make-instance without initialize-instance
- Index(es):
Relevant Pages
|