* equivalent of "this" in goops?
@ 2005-02-16 21:35 Greg Troxel
2005-02-16 23:07 ` Andreas Rottmann
0 siblings, 1 reply; 4+ messages in thread
From: Greg Troxel @ 2005-02-16 21:35 UTC (permalink / raw)
I'm using guile 1.6.x,and doing network mapping.
In a class representing a node, I want to have a slot with an
init-thunk, and I would like to call a procedure with the class object
as an argument. The slot holds a class object which is basically a
hash table of links in a network, and it needs the node object so it
can hash on 'other end node id'.
So, I'd like to pass 'this' in c++ terms, and I don't see how to do
that from reading goops.info. I realize there are issues with the
class not being fully initialized, and in my case that's safe since
I'm just storing the object in a variable and not using it until a
link is added, which doesn't happen during object initialization.
Thus I realize that what I want to do is vaguely unschemely.
My fallback is to initialize the linkset on first use, or after object
createion, or something like that.
--
Greg Troxel <gdt@ir.bbn.com>
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: equivalent of "this" in goops?
2005-02-16 21:35 equivalent of "this" in goops? Greg Troxel
@ 2005-02-16 23:07 ` Andreas Rottmann
2005-02-16 23:43 ` Neil Jerram
0 siblings, 1 reply; 4+ messages in thread
From: Andreas Rottmann @ 2005-02-16 23:07 UTC (permalink / raw)
Greg Troxel <gdt@ir.bbn.com> writes:
> I'm using guile 1.6.x,and doing network mapping.
>
> In a class representing a node, I want to have a slot with an
> init-thunk, and I would like to call a procedure with the class object
> as an argument. The slot holds a class object which is basically a
> hash table of links in a network, and it needs the node object so it
> can hash on 'other end node id'.
>
> So, I'd like to pass 'this' in c++ terms, and I don't see how to do
> that from reading goops.info. I realize there are issues with the
> class not being fully initialized, and in my case that's safe since
> I'm just storing the object in a variable and not using it until a
> link is added, which doesn't happen during object initialization.
> Thus I realize that what I want to do is vaguely unschemely.
FWICT (not being a GOOPS expert), this is not possible without
extending GOOPS: the init-thunk of a slot is specified at class
creation time, and the earliest time "this" is avaiable is in the
"initialize" generic. However, since the init-thunk is called at
initialization time, "this" would be available at the time it is run,
but there is no way to pass it, since the init-thunk, is, well, a
thunk ;). I could imagine a init-function (name to be argued), which
gets passed all arguments from "initialize" could be a useful
extension.
> My fallback is to initialize the linkset on first use, or after object
> createion, or something like that.
>
Given a GOOPS with this hypothetical extension is far from official
release ;), a workaround is probably the only feasibly short-term
solution (given my assumtion that this is not possible with current
GOOPS).
Cheers, Rotty
--
Andreas Rottmann | Rotty@ICQ | 118634484@ICQ | a.rottmann@gmx.at
http://yi.org/rotty | GnuPG Key: http://yi.org/rotty/gpg.asc
Fingerprint | DFB4 4EB4 78A4 5EEE 6219 F228 F92F CFC5 01FD 5B62
The best way to accelerate a Windows machine is at 9.81 m/s^2
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: equivalent of "this" in goops?
2005-02-16 23:07 ` Andreas Rottmann
@ 2005-02-16 23:43 ` Neil Jerram
2005-02-18 17:42 ` Greg Troxel
0 siblings, 1 reply; 4+ messages in thread
From: Neil Jerram @ 2005-02-16 23:43 UTC (permalink / raw)
Cc: guile-user
Andreas Rottmann wrote:
> Greg Troxel <gdt@ir.bbn.com> writes:
>
>>In a class representing a node, I want to have a slot with an
>>init-thunk, [...] So, I'd like to pass 'this' in c++ terms, and I don't see how to do
>>that from reading goops.info.
>
> FWICT (not being a GOOPS expert), this is not possible without
> extending GOOPS: the init-thunk of a slot is specified at class
> creation time, and the earliest time "this" is avaiable is in the
> "initialize" generic. However, since the init-thunk is called at
> initialization time, "this" would be available at the time it is run,
> but there is no way to pass it, since the init-thunk, is, well, a
> thunk ;). I could imagine a init-function (name to be argued), which
> gets passed all arguments from "initialize" could be a useful
> extension.
Absolutely right. Your best bet at this point is to customize the
initialize method for the class:
(define-method (initialize (this <node>) initargs)
(next-method)
(slot-set this 'name-of-slot-with-init-thunk
(init-function this)))
(It's probably also possible to use the MOP to support #:init-proc as a
new slot option, but that would require more thought.)
Regards,
Neil
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: equivalent of "this" in goops?
2005-02-16 23:43 ` Neil Jerram
@ 2005-02-18 17:42 ` Greg Troxel
0 siblings, 0 replies; 4+ messages in thread
From: Greg Troxel @ 2005-02-18 17:42 UTC (permalink / raw)
Cc: Andreas Rottmann, guile-user
Thanks very much for your suggestion. I now have the following (but
haven't tested yet):
;; set of links
(define-class <linkset> (<sinew-object>)
;; hash key is on other endpoint
(link-hash #:accessor link-hash
#:init-thunk (lambda () (make-hash-table 61)))
(my-node #:accessor my-node #:init-keyword my-node))
(define-class <node> (<sinew-object>)
[other stuff]
;; links is a set of links, findable by the other endpoint
(links-ip #:accessor links-ip)
(links-udaan #:accessor links-udaan))
;; override initialize in order to pass this to linkset constructor
(define-method (initialize (this <node>) initargs)
(next-method)
(slot-set this 'links-ip (make <linkset> #:my-node this))
(slot-set this 'links-udaan (make <linkset> #:my-node this))
--
Greg Troxel <gdt@ir.bbn.com>
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-02-18 17:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-16 21:35 equivalent of "this" in goops? Greg Troxel
2005-02-16 23:07 ` Andreas Rottmann
2005-02-16 23:43 ` Neil Jerram
2005-02-18 17:42 ` Greg Troxel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).