Re: Beginner's Clos question regarding :initform
From: Karl Pflästerer (sigurd_at_12move.de)
Date: 05/07/04
- Next message: Chris Hall: "Re: Modernizing Common Lisp"
- Previous message: nikodemus_at_random-state.net: "Re: Modernizing Common Lisp"
- In reply to: Kenny Tilton: "Re: Beginner's Clos question regarding :initform"
- Next in thread: Kenny Tilton: "Re: Beginner's Clos question regarding :initform"
- Reply: Kenny Tilton: "Re: Beginner's Clos question regarding :initform"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 07 May 2004 16:43:01 +0200
On 7 May 2004, Kenny Tilton <- ktilton@nyc.rr.com wrote:
> projects more often here on cll, so...wait till you see Cells. One
> incidental charm of that OO extension of mine is that one can indeed
> specify the value for a slot (via either initform or via initarg at
> make-instance time) with a form which is a function of the instance
> itself (hence can get to the other slots of the instance). The
That's exactly what I wanted. I think that is sometimes clearer (as you
can, when you read the code of the class, instantly see what's happening
at the time you create an instance without having to look for some
:around or :after methods).
> mechanism is one which has grander capabilities overall, but I find
> myself taking guilty pleasure all the time in just this little bit of
> fun (where 'self' is a smalltalk ripoff for the instance):
> (defclass button
> ((id :initarg :id :accessor id :initform (c? (class-of self)))
> (title$ :initarg :title$ :accessor title$
> :initform (c? (string (id self))))))
> Those would be easy enough to shift into initialize-instance, since
> they are being authored for the class. But one can also:
> (make-instance 'button
> :id (c? (intern
> (concatenate 'string
> "close-" (type-of (parent self)))))
> :title$ (c? (subsitute #\space #\- (string (id self))))
> :control-action (lambda (self) (close (parent self))))
> In this case initialize-instance would need help (a new slot with some
> sort of parameter) knowing which kind of initialization was desired.
> But with Cells one just codes it up without breaking one's stride.
That's really great. I think that way you can code in a very natural
way so you don't have to force the way you think to the way the language
behaves (for me Lisp code is written most of the time in a way I think
about a problem respectively its solution). That part of Clos didn't
behave that way but you show a solution how it can be writtten.
KP
--
'Twas brillig, and the slithy toves
Did gyre and gimble in the wabe;
All mimsy were the borogoves,
And the mome raths outgrabe. "Lewis Carroll" "Jabberwocky"
- Next message: Chris Hall: "Re: Modernizing Common Lisp"
- Previous message: nikodemus_at_random-state.net: "Re: Modernizing Common Lisp"
- In reply to: Kenny Tilton: "Re: Beginner's Clos question regarding :initform"
- Next in thread: Kenny Tilton: "Re: Beginner's Clos question regarding :initform"
- Reply: Kenny Tilton: "Re: Beginner's Clos question regarding :initform"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]