(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
* Matthew Economou wrote:
> 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
>>>>> "TB" == Tim Bradshaw <···@tfeb.org> writes:
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
Matthew Economou <········@irtnog.org> writes:
> >>>>> "TB" == Tim Bradshaw <···@tfeb.org> writes:
>
> 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.
--
Pierre Mai <····@acm.org> PGP and GPG keys at your nearest Keyserver
"One smaller motivation which, in part, stems from altruism is Microsoft-
bashing." [Microsoft memo, see http://www.opensource.org/halloween1.html]