Re: Reference and First-Class Function

Dimitre Novatchev <[email protected]> Sat, 20 Dec 2008 14:54:29 -0800 (PST)
Newsgroups gmane.text.xml.xslt.extensions
Message-ID <[email protected]>
> =

> Dimitre,
> =

> You may approach to this problem from two different perspectives:

=A0.............................


> 2. Postulate existance of references and indirect function calls,
> =A0 and derive closures from these constructs.

Vladimir,

There is no need to "postulate" the existence of references as they already=
 exist (in all programming languages I am aware of). Do you need to postula=
te that "water exists"?

We really have and use references in XPath, XSLT and I believe XQuery as a =
superset of XPath.Any =


=A0=A0 <xsl:sequence select=3D"someNode"/>

instruction produces a reference to that node, not a copy of it.

We have many statements from Dr. Kay himself, one of the most recent is pro=
bably=A0from this September in the thread in xsl-list "Benefits of xsl.sequ=
ence" :

http://www.stylusstudio.com/xsllist/200809/post50470.html

"Yes: this is the only way that you can write a function (or indeed a
template) that returns references to existing nodes"


And=A0there are=A0quite some of his statements to this effect through the y=
ears (the earliest I have seems to be from 2003).

Another source of statements that we have been using references all the tim=
e in XSLT 2.0 are the books of Dr. Kay.

To quote Dr. Kay's book "XSLT 2.0 and XPath 2.0=A0 4th edition Programmer's=
 Reference",=A0 ISBN: 978-0-470-19274-0, page 452:

"The <xsl:sequence> instruction ... is the only XSLT instruction (with the =
exception of <xsl:perform-sort>) that can return references to existing nod=
es, as distinct from newly constructed nodes."

Identical text is on page 420 of Dr. Kay's book "XSLT 2.0 3rd edition Progr=
ammer's Reference" (ISBN: 0-764-56909-0)

So, references do exist in XPath and XSLT, they=A0are held in a variables a=
nd returned from functions. The only problem is whenever we want to store t=
hem in an XML document or use a reference to a sequence as an atomic item i=
nside another sequence. =


There is no problem of defining a "reference" type without closures and the=
 whole attempt to invent references through closures is incorrect and artif=
icial. References were there all the way, we were happily using them withou=
t ever complaining that they lacked closures.=A0 =


References exist and are used in most XSLT 2.0 transformations. We don't ne=
ed to postulate anything -- just use what we already have in a more formal =
definition of the "reference" type.


The issue I have raised is that any attempt to define references based on c=
losures ignores the fact that closures are defined using references -- this=
 is a circular definition and it expands infinitely (like infinite recursio=
n) and fails to define anything.

As I said before:

> The definition of closure uses references, so it is not what Dr. Kay is s=
peaking =

> about.
> =

> Therefore, it would be correct if Dr. Kay stops calling "closure" the thi=
ng he =

> is talking about, rename it to something else, and most importantly, show=
 how =

> this "something else" can create a reference out of thin air.



Cheers,
Dimitre



> =

> =

> > > Once again, closures "have references" to external variables.
> > =

> > > As I said even in my previous message, a closure contains a
> > > reference.
> > =

> > Or put in another way: if you get closures, you get references.
> =

> This statement ignores the fact that the term "reference" is used in the =

> definition of "closure" I quoted the definition of closure from Wikipedia=
 and =

> the places where the term "reference" is used.
> =

> =

> > =

> > > A closure relies on the concept of reference being already
> > > implemented.
> > =

> > I wouldn't put it like that. Closures does not rely on the feature
> > of reference being available in the language, even if their
> > implementation needs to provide that in some way.
> =

> A very interesting statement... :) So, we confess of having to use refere=
nces =

> ... from somewhere...???
> =

> Then we deny references existed when we used them...
> =

> Then we say: We give you references *for free* !
> =

> This made my day, Thank you.
> =

> =

> > =

> > And as Michael showed us, if you get closures, you get references for
> > free.
> =

> Of course -- as you already have *references* inside the closure!
> =

> Dr. Kay did't show anything. He expressed his believes on the topic.
> =

> On the other side, I provided quotes to the definition of closure. This i=
s not =

> my belief, but the oficial definition.
> =

> The definition of closure uses references, so it is not what Dr. Kay is s=
peaking =

> about.
> =

> Therefore, it would be correct if Dr. Kay stops calling "closure" the thi=
ng he =

> is talking about, rename it to something else, and most importantly, show=
 how =

> this "something else" can create a reference out of thin air.
> =

> =

> =

> _______________________________________________
> exslt mailing list
> [email protected]
> http://www.exslt.org/list



      =