Ocaml binding innards (was Re: [gdome]user_data and language bindings)

Hi Claudio and list members,

please be patient with me, I really want to understand what is going on in
the ocaml binding.

On Fri, 5 Apr 2002, Claudio Sacerdoti Coen wrote:
> > And then, obj' and newChild are just two names for the same object,
> > because of some feature in ocaml?
>  Not exactly. newChild is the OO wrapper, while obj' is the pre-method this.

I wanted to ask a different question, and got a bit confused:
The object returned by "new node obj'" and the object refered to by
"newChild" are the very same object inside Ocaml for this particular
method (insertBefore), and not two different Ocaml objects that happen to
represent the same Gdome node?

>  If you want (roughly!!) newChild is the ocaml object while obj' is the
>  gdome "object".

Ok, I've got this.

> > >     To sum up, we have two "functions" (the constructor and as_node)
> > >     to map "this" of the pre-method level to objects at the OO-level.
> > >     A method M at the OO level is the composition of a constructor
> > >     with the pre-method M' with the as_node method.
> >
> > Ok, how is this mapping performed in the constructor? Using a per-document
> > this-to-OO hash table or something?
>  Not at all. Simply, the constructor stores the "this" in a field of
>  the object. (Roughly: in Ocaml you don't have to store fields because
>  you have closures...) So, every time you call a method of the object,
>  the method implementation retrieves the "this" and calls the
>  pre-methods on the this and the arguments.

Then I rushed out a bit two fast in my last mail. What I understand from
this paragraph is that in
n1 = someNode.firstChild
n2 = someNode.firstChild
(in whatever Syntax is appropriate for Ocaml),
n1 and n2 are different Ocaml objects that happen to wrap the same gdome
node. With different I mean, they would fail at least some of Ocaml's
equality/identity tests.

But I am almost certain that this is still somewhat wrong and that you
will correct (and enlight) me here.

>  Of course. My remark was just that to complete the binding I have no
>  need at all for the hash table, because of the "trick" of the
>  OO-objects remembering the "this" without need of any hash-table.
>  So I have not really implemented the hash-table stuff, but it can be
>  implemented if someone needs this (e.g. for subclassing Ocaml objects).

I think this paragraph fits nicely with my new understanding of the

>  I don't know if you can do the same easily in other languages
>  (i.e. I don't know if you will need the hash table just to be able to
>  complete the binding.)

Ok, now I looked at my wrapper code, and found that in the last release I
do not make use of the user_data pointer, but I have changed that in the
cvs version, to avoid having multiple Ruby objects wrap the same gdome

If I understood correctly this time what you do in ocaml, then I did the
same in ruby in the last release, but wanted to make it more efficient by
the use of the user_data pointer in the next release (by avoiding
mulltiple wrapper objects per gdome node).


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]