Re: About node references

Florent Georges <[email protected]> Tue, 16 Dec 2008 18:41:59 +0100 (CET)
Newsgroups gmane.text.xml.xslt.extensions
Message-ID <[email protected]>
Dimitre Novatchev wrote:

  Thanks for your perseverance :-)  However...

> >   I must admit I am a bit lost.  If items can be garbage-collected
> > when there is no more Ref "pointing" to them, what's the point to
> > have a copy function?

> The point is to give a new Ref to someone else, so they will be able
> to deref it, even thow the original Ref has been destroyed. That is,
> to ensure that the item will *not* be garbage-collected. Or, to quote
> the original message once again:

> "Additionally, we have the function:

>   Ref       xx:copyRef(Ref ref1)    From an object ref1 = (strKey1,
> memRef1)  produces an object ref 2 = (strKey2, memRef2), such that
> memRef2 = memRef1

> The important thing here is that we have created a second memRef to
> the same item. If now ref1 goes out of scope and is destroyed, ref2
> may still be in scope and thus its memRef will ensure the item being
> referenced is not going to be garbage-collected."

  But I am still confused.  What do you mean by "someone else" above?
If you can pass the copied Ref to someone else, why can't you pass the
original Ref?

> >  And if the Ref object must be kept to ensure it is still
> > dereferenceable, what is the string used for?

> The string represents uniquely the Ref object. It can be stored as a
> text node and carried arround. We can deref() it:

>   xx:deref(xx:getRef(strKey))

> and get to the original item or sequence that was ref-ed.

  So either 1/ you don't know nothing about the Ref anymore (because
say you added the string to an XML tree and only pass that tree) so you
don't know if there are any Ref still in scope pointing to the items,
so you don't know if you can still get a valid Ref from the string, or
2/ you do know there is still a valid Ref in scope for that string, but
in that case, why wouldn't you use directly the Ref?

> As we can see, it is not at all necessary to use a higher order
> function in order to be able to implement a reference in XPath.

  Sure, we agree.  Using a first-class function object was just an idea
suggested by Michael to represent the type of Ref, and I found it
interesting.  Let's say that it is just one possible way to represent
the Ref, and to dereference it.  But I think this is not at all the
heart of the feature (while it could be convenient I think.)

  Regards,

-- 
Florent Georges
http://www.fgeorges.org/