What's the equivalent of C++'s "this" for CLOS? I have an :initform that
I want to be computed from the value of another slot in the same object.
More concretely, I want a window to take default width and height values
from the screen it's on, and the screen is the first and only :initarg
of the window.
Can this be done in an :initform or is this a job for (defmethod
initialize-instance :after ..) ?
--
Cyborg Animation Programmer
http://yagc.blogspot.com
http://badbyteblues.blogspot.com
John Connors <·····@yagc.dot.ndo.dot.co.dot.uk> writes:
> What's the equivalent of C++'s "this" for CLOS? I have an :initform
> that I want to be computed from the value of another slot in the same
> object.
> More concretely, I want a window to take default width and height
> values from the screen it's on, and the screen is the first and only
> :initarg of the window.
>
> Can this be done in an :initform or is this a job for (defmethod
> initialize-instance :after ..) ?
You need INITIALIZE-INSTANCE.
-Peter
--
Peter Seibel ·····@javamonkey.com
Lisp is the red pill. -- John Fraser, comp.lang.lisp
John Connors <·····@yagc.dot.ndo.dot.co.dot.uk> writes:
> What's the equivalent of C++'s "this" for CLOS?
In C++ methods are attached to a single class.
In CLOS, methods area attached to generic functions, and generic
function are dispatched over all their arguments. There is no
distinguised 'self' or 'this' object in CLOS.
If you really insist on it, you can always take your own convention
that the first argument of a generic function is 'this':
(defgeneric move-view (this x y))
(defmethod move-view ((this window) (x integer) (y integer)) ...)
(defmethod move-view ((this view) (x integer) (y integer)) ...)
(defmethod move-view ((this point) (x integer) (y integer)) ...)
But in these cases, I prefer to use self (since I prefer Smaltalk to C++).
> I have an :initform
> that I want to be computed from the value of another slot in the same
> object.
The problem is that there is no lexical environment where to write
this initform to get a 'this' from.
> More concretely, I want a window to take default width and height
> values from the screen it's on, and the screen is the first and only
> :initarg of the window.
>
> Can this be done in an :initform or is this a job for (defmethod
> initialize-instance :after ..) ?
Yes, you'll need to write an initialize-instance method.
--
__Pascal Bourguignon__ http://www.informatimago.com/
The mighty hunter
Returns with gifts of plump birds,
Your foot just squashed one.
Pascal Bourguignon wrote:
> John Connors <·····@yagc.dot.ndo.dot.co.dot.uk> writes:
>
>
>>What's the equivalent of C++'s "this" for CLOS?
>
>
> In C++ methods are attached to a single class.
>
> In CLOS, methods area attached to generic functions, and generic
> function are dispatched over all their arguments. There is no
> distinguised 'self' or 'this' object in CLOS.
>
> If you really insist on it, you can always take your own convention
> that the first argument of a generic function is 'this':
>
> (defgeneric move-view (this x y))
>
> (defmethod move-view ((this window) (x integer) (y integer)) ...)
> (defmethod move-view ((this view) (x integer) (y integer)) ...)
> (defmethod move-view ((this point) (x integer) (y integer)) ...)
>
> But in these cases, I prefer to use self (since I prefer Smaltalk to C++).
>
>
>>I have an :initform
>>that I want to be computed from the value of another slot in the same
>>object.
>
>
> The problem is that there is no lexical environment where to write
> this initform to get a 'this' from.
>
>
>
>>More concretely, I want a window to take default width and height
>>values from the screen it's on, and the screen is the first and only
>>:initarg of the window.
>>
>>Can this be done in an :initform or is this a job for (defmethod
>>initialize-instance :after ..) ?
>
>
> Yes, you'll need to write an initialize-instance method.
It is so sad after all these years of blanket marketing of Cells to
discover you and Peter blathering away so ignorantly about the potential
of Common Lisp and CLOS to perform with an order of magnitude more power
than you seem to know about.
The fact is that one can not only code:
(defclass rectangle ()
((length...)
(width ...)
(area :initform (c? (* (length self)(width self))))))
But one can also code:
(list (make-instance 'shape :area (c? (expt (elt (sides self) 0) 2)))
(make-instance 'shape :area (c? (* (elt (sides self) 0)
(elt (sides self 1)))))
C'mon, try to keep up, will ya?
:)
kt
--
Cells? Cello? Celtik?: http://www.common-lisp.net/project/cells/
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
Kenny Tilton wrote:
(SNIP, SNIP)
>
> The fact is that one can not only code:
>
> (defclass rectangle ()
> ((length...)
> (width ...)
> (area :initform (c? (* (length self)(width self))))))
>
> But one can also code:
>
> (list (make-instance 'shape :area (c? (expt (elt (sides self) 0) 2)))
> (make-instance 'shape :area (c? (* (elt (sides self) 0)
> (elt (sides self 1)))))
>
What's c? I can't find it in the Hyperspec..doing a google for :initform
self took me to an entry about Cells on Bill Clementson's blog ;)
> C'mon, try to keep up, will ya?
>
> :)
>
> kt
>
--
Cyborg Animation Programmer
http://yagc.blogspot.com
http://badbyteblues.blogspot.com
On Sat, 08 Jan 2005 23:35:43 +0000, Kenny Tilton <·······@nyc.rr.com> wrote:
> It is so sad after all these years of blanket marketing of Cells
> [...]
On Sun, 09 Jan 2005 08:27:03 +0000, John Connors <·····@yagc.dot.ndo.dot.co.dot.uk> wrote:
> What's c? I can't find it in the Hyperspec..doing a google for
> :initform self took me to an entry about Cells on Bill Clementson's
> blog ;)
You mean it'd be helpful if Cells were documented? Hmmm, that's a
plan...
Kenny!!!!
--
Lisp is not dead, it just smells funny.
Real email: (replace (subseq ·········@agharta.de" 5) "edi")
Edi Weitz wrote:
> On Sat, 08 Jan 2005 23:35:43 +0000, Kenny Tilton <·······@nyc.rr.com> wrote:
>
>
>>It is so sad after all these years of blanket marketing of Cells
>>[...]
>
>
> On Sun, 09 Jan 2005 08:27:03 +0000, John Connors <·····@yagc.dot.ndo.dot.co.dot.uk> wrote:
>
>
>>What's c? I can't find it in the Hyperspec..doing a google for
>>:initform self took me to an entry about Cells on Bill Clementson's
>>blog ;)
>
>
> You mean it'd be helpful if Cells were documented? Hmmm, that's a
> plan...
>
> Kenny!!!!
haha, well, to be honest, there has not been enough interest in Cells to
justify the effort to write formal doc! And my chosen method of
generating interest was to create Cello, not doc. And that kinda took on
a life of its own.
I had planned to develop doc in response to questions from early
adopters, but those happy few seem to have gotten by with ... well, I do
not know what they used. Possibly random stuff here:
http://www.tilton-technology.com/cells_top.html
I do not believe anyone has ever sent me an email asking how any aspect
of cells works. I guess early adopters just look at the Cells source or
something. I know Vasilis of cells-gtk fame started from my cells+ltk code.
Hang on. One gent sent me some cyclic (failing) cells code and we worked
thru a solution (found a non-cyclic algorithm). So that at least started
as a Cells question.
Let's face it: Cells has failed to capture the hearts and minds of
Lispniks. May as well plow it under.
kt
--
Cells? Cello? Celtik?: R.I.P.
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
On Sun, 09 Jan 2005 16:46:40 GMT, Kenny Tilton <·······@nyc.rr.com> wrote:
> haha, well, to be honest, there has not been enough interest in
> Cells to justify the effort to write formal doc!
It's a chicken-and-egg problem, I think.
> Let's face it: Cells has failed to capture the hearts and minds of
> Lispniks. May as well plow it under.
I'm not so sure. I checked it when it was pretty new and thought that
it looked quite promising but that I don't have the time to work on
it. I was like "Let's wait until they're out of the alpha stage."
Then I looked again some time later and what I could read about Cells
still looked very much the same. (I'm sure the code had changed
considerably but I'm not supposed to keep older versions and diff
them, am I?)
Anyway, you could have won the heart and mind of at least this
particular Lispnik if there had been enough documentation to start
with - i.e. a) installation instructions that work, b) a survey about
what Cells do and what they don't, c) some tutorial-style examples, d)
a complete reference of all function, macros, variables, etc.
Edi.
--
Lisp is not dead, it just smells funny.
Real email: (replace (subseq ·········@agharta.de" 5) "edi")
Edi Weitz <········@agharta.de> writes:
> On Sun, 09 Jan 2005 16:46:40 GMT, Kenny Tilton <·······@nyc.rr.com> wrote:
>
>> haha, well, to be honest, there has not been enough interest in
>> Cells to justify the effort to write formal doc!
>
> It's a chicken-and-egg problem, I think.
>
>> Let's face it: Cells has failed to capture the hearts and minds of
>> Lispniks. May as well plow it under.
>
> I'm not so sure. I checked it when it was pretty new and thought that
> it looked quite promising but that I don't have the time to work on
> it. I was like "Let's wait until they're out of the alpha stage."
> Then I looked again some time later and what I could read about Cells
> still looked very much the same. (I'm sure the code had changed
> considerably but I'm not supposed to keep older versions and diff
> them, am I?)
>
> Anyway, you could have won the heart and mind of at least this
> particular Lispnik if there had been enough documentation to start
> with - i.e. a) installation instructions that work, b) a survey
> about what Cells do and what they don't, c) some tutorial-style
> examples, d) a complete reference of all function, macros,
> variables, etc.
Likewise. I checked back to your web site several times but eventually
gave up when I didn't see any path to understanding short of
grovelling through the source itself. Which I would have been happy to
do if I had had something to read first to convince me it was worth
the effort.
-Peter
--
Peter Seibel ·····@javamonkey.com
Lisp is the red pill. -- John Fraser, comp.lang.lisp
Peter Seibel wrote:
> Edi Weitz <········@agharta.de> writes:
>
>
>>On Sun, 09 Jan 2005 16:46:40 GMT, Kenny Tilton <·······@nyc.rr.com> wrote:
>>
>>
>>>haha, well, to be honest, there has not been enough interest in
>>>Cells to justify the effort to write formal doc!
>>
>>It's a chicken-and-egg problem, I think.
>>
>>
>>>Let's face it: Cells has failed to capture the hearts and minds of
>>>Lispniks. May as well plow it under.
>>
>>I'm not so sure. I checked it when it was pretty new and thought that
>>it looked quite promising but that I don't have the time to work on
>>it. I was like "Let's wait until they're out of the alpha stage."
>>Then I looked again some time later and what I could read about Cells
>>still looked very much the same. (I'm sure the code had changed
>>considerably but I'm not supposed to keep older versions and diff
>>them, am I?)
>>
>>Anyway, you could have won the heart and mind of at least this
>>particular Lispnik if there had been enough documentation to start
>>with - i.e. a) installation instructions that work, b) a survey
>>about what Cells do and what they don't, c) some tutorial-style
>>examples, d) a complete reference of all function, macros,
>>variables, etc.
>
>
> Likewise. I checked back to your web site several times but eventually
> gave up when I didn't see any path to understanding short of
> grovelling through the source itself. Which I would have been happy to
> do if I had had something to read first to convince me it was worth
> the effort.
Oh, so you never made to Bill's blog? Anyway, really, Cells is not worth
the trouble. Screamer+ or KR or COSI are the way to go. Or, my real
point originally, do a couple hours' macrology and you too can have
initforms or initarg forms which enjoy access to a self-ish anaphor
bound to the instance being instantiated.
The larger point is that "initialize-instance" is lame even where it
will work, and in many cases does not even suffice when one is hoping to
intialize an instance based on other attributes of the same instance[1].
kt
[1] Where the instance happens to have a slot such as "parent" which
links it to the rest of the application model, initialization actually
can see as far as the model stretches. hellasweet.
>
> -Peter
>
--
Cells? Cello? Celtik?: http://www.common-lisp.net/project/cells/
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
Kenny Tilton <·······@nyc.rr.com> writes:
[...]
> Let's face it: Cells has failed to capture the hearts and minds of
> Lispniks. May as well plow it under.
I'm not sure. My suspicion is that Cells is the kind of thing that
you just make a mental note of (as something interesting but not
serving any immediate need) but after you got around to using it once,
will never want to live without. Not unlike LOOP, or, for that matter,
Common Lisp itself.
Andras
Andras Simon wrote:
> Kenny Tilton <·······@nyc.rr.com> writes:
>
> [...]
>
>>Let's face it: Cells has failed to capture the hearts and minds of
>>Lispniks. May as well plow it under.
>
>
> I'm not sure. My suspicion is that Cells is the kind of thing that
> you just make a mental note of (as something interesting but not
> serving any immediate need) but after you got around to using it once,
> will never want to live without. Not unlike LOOP, or, for that matter,
> Common Lisp itself.
One thing cells-alikes have in common with CL is that the idea is too
correct to die. For good, I mean. They have died more than once, but
they always come back.
Cells may be dead, but the idea is doing fine and living in Miami.
kt
--
Cells? Cello? Celtik?: Ashes? Dust?
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
Kenny Tilton <·······@nyc.rr.com> writes:
> Let's face it: Cells has failed to capture the hearts and minds of
> Lispniks.
Every time I see you post a Cells example I get excited, as it just
seems like an idea that should exist. You once shared some code
written for one of your NYC pub meetings where you implemented
mini-Cells from scratch. Though incomplete, it made for rewarding
study.
I still have yet to actually use Cells in a project. My hangup: I
wasn't comfortable using such "magic" until I could understand how it
works. I had downloaded the source and started picking through it,
making notes, and had a few "aha!" moments, but several pressing
distractions killed that momentum. The code had the feel of a mad
genius taping things together -- strange names, silly comments,
workarounds, some dead code -- all evidence that something amazing was
being discovered, worked out and working at the same time. For anyone
other than the author, though, it requires intense concentration to
hold the constituent ideas in mind.
My solution was to try to rewrite it, or at least sketch something
small that allowed me to learn how certain essential parts went
together. The aim is not to replace it, but to emulate it with my own
hand. Then, with enough of it understood, I could abandon my sketch
and use, or even contribute to, the real Cells project.
It remains high on my list of things to dig into again.
--
Steven E. Harris
Steven E. Harris wrote:
> Kenny Tilton <·······@nyc.rr.com> writes:
>
>
>>Let's face it: Cells has failed to capture the hearts and minds of
>>Lispniks.
>
>
> Every time I see you post a Cells example I get excited, as it just
> seems like an idea that should exist. You once shared some code
> written for one of your NYC pub meetings where you implemented
> mini-Cells from scratch. Though incomplete, it made for rewarding
> study.
That was a ball, making it up as I went along with the non-Lispnik
audience (who had come for an intro to Lisp!) shouting out helpful
suggestions any time I got stuck.
>
> I still have yet to actually use Cells in a project. My hangup: I
> wasn't comfortable using such "magic" until I could understand how it
> works. I had downloaded the source and started picking through it,
> making notes, and had a few "aha!" moments, but several pressing
> distractions killed that momentum. The code had the feel of a mad
> genius taping things together -- strange names, silly comments,
> workarounds, some dead code --
Don't forget all those debug statements featured out but still visually
overwhelming the actual code, which in some stretches they outnumber!
Lawdy, I would love to clean those out, but then I would just have to
put them all back in the next time I got the hood up. Hmmm, maybe I am
being too lazy. Contrary to the conventional wisdom, the hack /is/
stable. (I think the "unfinished-business" sub-hack must have been
Deeply Correct -- I should fire up RoboCells to see, since that somehow
knocked the old algorithm to its knees, one that had been adequate to a
large variety of production code.)
> -- all evidence that something amazing was
> being discovered, worked out and working at the same time.
<g> thanks, but that should be rediscovered and re-worked out. Cells is
old news, I was just ignorant of the prior art.
>... For anyone
> other than the author, though, it requires intense concentration to
> hold the constituent ideas in mind.
You should have seen the code in the early days. Omigod! I almost went
shopping.
>
> My solution was to try to rewrite it, or at least sketch something
> small that allowed me to learn how certain essential parts went
> together. The aim is not to replace it, but to emulate it with my own
> hand. Then, with enough of it understood, I could abandon my sketch
> and use, or even contribute to, the real Cells project.
>
> It remains high on my list of things to dig into again.
>
We programmers are such hermits. Over the years it seems several
Lispniks have thrown up their hands in despair at ever making sense of
the code and several other Lispniks have simply dived in and done
substantial projects using Cells, all without ever making one post to
the Cells list or contacting me. Cowboys!
Wait. I did have a great exchange with a young man I met at ILC2003 who
really tore into Cells, identifying a troublesome edge case, and he too
quickly lost interest in Cells and wrote his own hack from scratch. That
was fun, and got me motivated to do Cells II (when "unfinished-business"
made the "II" appropriate). that was fun.
thx for the continued interest. But one swallow does not a summer make.
I am looking at a career in snowboard instruction now. Ever to try to
fit a rhesus with snowboard boots?
:)
kenny
--
Cells? Cello? Celtik?: http://www.common-lisp.net/project/cells/
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
John Connors wrote:
> Kenny Tilton wrote:
>
> (SNIP, SNIP)
>
>>
>> The fact is that one can not only code:
>>
>> (defclass rectangle ()
>> ((length...)
>> (width ...)
>> (area :initform (c? (* (length self)(width self))))))
>>
>> But one can also code:
>>
>> (list (make-instance 'shape :area (c? (expt (elt (sides self) 0) 2)))
>> (make-instance 'shape :area (c? (* (elt (sides self) 0)
>> (elt (sides self 1)))))
>>
> What's c? I can't find it in the Hyperspec..
Look again. It's right after FFI, sockets, the MOP, CLIM, and threads. :)
> ...doing a google for :initform
> self took me to an entry about Cells on Bill Clementson's blog ;)
Oh, good, you found it. :)
kt
--
Cells? Cello? Celtik?: http://www.common-lisp.net/project/cells/
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
Pascal Bourguignon <····@mouse-potato.com> writes:
> John Connors <·····@yagc.dot.ndo.dot.co.dot.uk> writes:
>
> > What's the equivalent of C++'s "this" for CLOS?
>
> In C++ methods are attached to a single class.
>
> In CLOS, methods area attached to generic functions, and generic
> function are dispatched over all their arguments. There is no
> distinguised 'self' or 'this' object in CLOS.
>
> If you really insist on it, you can always take your own convention
> that the first argument of a generic function is 'this':
>
> (defgeneric move-view (this x y))
>
> (defmethod move-view ((this window) (x integer) (y integer)) ...)
> (defmethod move-view ((this view) (x integer) (y integer)) ...)
> (defmethod move-view ((this point) (x integer) (y integer)) ...)
>
> But in these cases, I prefer to use self (since I prefer Smaltalk to C++).
When I do that, I also call it "self", because that's what Flavors called it.
(Flavors was like Smalltalk: you SEND a message to an object, and the method
has lexical access to the instance variables, but it was multiple-inheritence;
it's one of the predecessors of CLOS.)
John Connors <·····@yagc.dot.ndo.dot.co.dot.uk> writes:
> Can this be done in an :initform or is this a job for (defmethod
> initialize-instance :after ..) ?
Others have already answered "yes" to this, but I would recommend
putting the method on SHARED-INITIALIZE.
--
Rahul Jain
·····@nyct.net
Professional Software Developer, Amateur Quantum Mechanicist