Q: extending MAKE-INSTANCE? 
Author Message
 Q: extending MAKE-INSTANCE?

(Thanks for your help with the previous question, Erik, and my
apologies about the screwball example.)

I have another question.  I don't really understand CLOS all that
well, and the stuff about customizing MAKE-INSTANCE in the CLHS
(section 7.1.7) confuses me.

Would someone post an example of a class with a customized
MAKE-INSTANCE?

(One of the slots of my class contains a closure that needs to refer
back to the particular instance that contains it.)

--
"I'm very busy.  I'm preparing my next mistake." -- B. Brecht



Fri, 26 Apr 2002 03:00:00 GMT  
 Q: extending MAKE-INSTANCE?

Quote:

> Would someone post an example of a class with a customized
> MAKE-INSTANCE?
> (One of the slots of my class contains a closure that needs to refer
> back to the particular instance that contains it.)

I think I'd do that with INITIALIZE-INSTANCE:

    (defclass foo ()
        ((fn :reader foo-fn)    ; FN takes one arg: the instance
         (slot :reader foo-slot
               :initarg :slot
               :initform nil)))

    (defmethod initialize-instance :after ((f foo) &key (fn #'identity))
      (setf (slot-value f 'fn)
            #'(lambda ()
                (funcall fn f))))

    (funcall (foo-fn (make-instance 'foo :slot 3
                                         :fn #'(lambda (e)
                                                 (slot-value e 'slot)))))
    -> 3

--tim



Fri, 26 Apr 2002 03:00:00 GMT  
 Q: extending MAKE-INSTANCE?

    TB> I think I'd do that with INITIALIZE-INSTANCE:

I don't understand your answer, but that's because I'm not familiar
with CLOS.  I'm going to go looking for a CLOS tutorial, and maybe get
a copy of AMOP while I'm at it.

Thanks for your help!

--
"I'm very busy.  I'm preparing my next mistake." -- B. Brecht



Sat, 27 Apr 2002 03:00:00 GMT  
 Q: extending MAKE-INSTANCE?

Quote:


>     TB> I think I'd do that with INITIALIZE-INSTANCE:

> I don't understand your answer, but that's because I'm not familiar
> with CLOS.  I'm going to go looking for a CLOS tutorial, and maybe get
> a copy of AMOP while I'm at it.

Also try to get hold of a copy of Sonya E. Keene's book on CLOS, which
together with the AMOP should give you a pretty good insight into
CLOS, the MOP and their philosophy:

* Keene, Sonya E.: Object Oriented Programming in Common Lisp
  - A Programmers Guide to the Common Lisp Object System (on order)
  http://www.amazon.de/exec/obidos/ASIN/0201175894/

The above link to amazon.de (replace with amazon.com for the US) is
not part of any partnership program.

Regs, Pierre.

--

  "One smaller motivation which, in part, stems from altruism is Microsoft-
   bashing." [Microsoft memo, see http://www.opensource.org/halloween1.html]



Sat, 27 Apr 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Array.extend versus instance.extend

2. how to extend an instance of visual class: was using RADs in OO way

3. Embedding: how to extend a C++ instance by Python methods

4. Deriving from builtin types with limited instances and Extending FAQ 6.6

5. Deriving from builtin types with limited instances and Extending FAQ 6.6

6. Making Mu an instance of Functor??

7. Making sure only one instance of a program is running

8. instances of classes and instances of instances

9. A question about making a copy of an instance of an object

10. Can event from instance propagate to other instances?

11. range(Instance) vs. foo[Instance]

12. Instances incorrectly sharing instance variables?

 

 
Powered by phpBB® Forum Software