<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hello,</div><div><br></div><div><div>First, as an XQuery user (but this is only my opinion), object orientation (or as you call it item-orientation) is a feature which I would appreciate to have in XQuery.</div><div><br></div><div>Here are a couple of words regarding implementation.</div><div><br></div><div>In my research group, we are actually working on a project about object orientation in XQuery, called Unity. We did not go into dynamic binding or polymorphism, but basically, we simply tried to introduce code in the schema to allow constructs like, following your idea:</div></div><div><br></div><div>$triangle/rotate()</div><div><br></div><div>where the context item is passed as a hidden parameter to the method rotate. The method rotate is defined in the schema for the static type of $triangle.</div><div><br></div><div>To put code in the schema, we added "classes" to the XQuery syntax. A class is simply a complex type definition written in (a text-version of) XML Schema, containing, in addition to elements and attributes, also methods. In these methods, unlike in (most) XQuery functions, the context item is defined. Of course, an alternative way would be to really use XML Schema in its original XML format and define methods separately in an XQuery file.</div><div><br></div><div><br></div><div>For example, a complex type containing code could be defined with code like:</div><div><br></div><div><div>declare class HanoiProblem {</div><div>&nbsp;&nbsp; &nbsp;element numOfTowers as xs:positiveInteger occurs 1-1; (: we did not reinvent the wheel, this is just a text version of XML Schema (here, implicitely a sequence) :)</div><div>&nbsp;&nbsp; &nbsp;element src as xs:string occurs 1-1;</div><div>&nbsp;&nbsp; &nbsp;element aux as xs:string occurs 1-1;</div><div>&nbsp;&nbsp; &nbsp;element dst as xs:string occurs 1-1;</div><div><br></div><div>&nbsp;&nbsp; &nbsp;method solution() {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>solve(getTowers(), src, aux, dst)</div><div>&nbsp;&nbsp; &nbsp;}</div><div><br></div><div>&nbsp;&nbsp; &nbsp;method solve($n as xs:integer, $src as xs:string, $aux as xs:string, $dst as xs:string) {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if ($n eq 0)&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;then &nbsp;()</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;else (</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-tab-span" style="white-space:pre">        </span>solve($n -1, $src, $dst, $aux),</div><div>&nbsp;&nbsp; &nbsp; &nbsp;<span class="Apple-tab-span" style="white-space:pre">                </span>move($src, $dst),</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-tab-span" style="white-space:pre">        </span>solve($n -1, $aux, $src, $dst)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>)</div><div>&nbsp;&nbsp; &nbsp;</div><div>&nbsp;&nbsp; &nbsp;}</div><div><br></div><div>&nbsp;&nbsp; &nbsp;method move($src as xs:string,$dest as xs:string) {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&lt;move></div><div><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &lt;source>{$src}&lt;/source></div><div><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &lt;destination>{$dest}&lt;/destination></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&lt;/move></div><div>&nbsp;&nbsp; &nbsp;}</div><div><br></div><div>&nbsp;&nbsp; method getTowers() as xs:integer{</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;numOfTowers<span class="Apple-tab-span" style="white-space:pre">        </span></div><div>&nbsp;&nbsp; &nbsp;}</div><div>};</div><div><br></div><div>And it could be used with code like:</div><div><br></div><div>let $hanoiProblemInstance as element(my:HanoiProblem) := fn:doc("hanoi.xml")/my:hanoi</div><div>let $n := $hanoiProblemInstance/my:getTowers()</div><div>let $solution := &lt;solution forN = "{$n}">{$hanoiProblemInstance/my:solution()}&lt;/solution><span class="Apple-tab-span" style="white-space:pre">        </span></div><div>return $solution</div><div><br></div></div><div><br></div><div>We have implemented a cross-compiler which compiles Unity code to XQuery+XML Schema, and could test the output successfully with Saxon SA on several examples. We did not encounter any major issues during the implementation. One issue could be a name collision between a method and a function, which can be solved by looking at methods for the static type of the context item first, and then at functions.</div><div><br></div><div>We are now thinking of adding this functionality to an existing schema-aware XQuery engine to see how it performs.</div><div><br></div><div>Of course I would also be happy to hear comments on object-orientation in XQuery. Perhaps other research groups are also working on this topic?</div><div><br></div><div>Kind regards,</div><div>Ghislain Fourny</div><div><br></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: 14px; white-space: pre; "><div class="footer signature" style="font-family: Arial, Helvetica, 'Luxi Sans', sans-serif; font-style: italic; white-space: pre; "><div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">
</div></div><div class="quote quote-1" style="font-family: Arial, Helvetica, 'Luxi Sans', sans-serif; padding-left: 10px; color: blue; border-left-width: 2px; border-left-style: solid; border-left-color: blue; "><div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">-----Original Message-----
From: <span>talk<a class="email" style="color: rgb(0, 0, 153); text-decoration: underline; font-size: 0.9em; cursor: pointer; ">...</a>@x-query.com</span> 
[mailto:<span>talk<a class="email" style="color: rgb(0, 0, 153); text-decoration: underline; font-size: 0.9em; cursor: pointer; ">...</a>@x-query.com</span>] On Behalf Of Hans-Juergen Rennau
Sent: 20 January 2009 07:47
To: <span>ta<a class="email" style="color: rgb(0, 0, 153); text-decoration: underline; font-size: 0.9em; cursor: pointer; ">...</a>@x-query.com</span>
Subject: [xquery-talk] XQuery and Item Orientation

</div><div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Hello People,

</div><div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">I would like to learn about your thoughts about a perspective 
of introducing "item orientation" - an echo of object 
orientation - into XQuery.

</div><div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Starting point: in my opinion, software development has 
undergone two revolutions: object orientation, and 
XML/XPath/XQuery, both acting as reducers of complexity. 
Suddenly it appears strange to me that XQuery makes no 
attempt to incorporate object oriented features. More 
concretely, I think of binding functionality to a) type and 
b) instance. Imagine a second kind of function were 
introduced into the language, call it itemFunction, which is 
invoked like an object's member function, where the "object" 
is an item:
   $triangle->rotate()
or
   $triangles/.->rotate()

</div><div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Within the function body, the item is available as the 
context item expression (its top level uses, of course). So 
much for the binding to an instance. Now the binding to a 
type. This amounts to some sort of test used to select the 
appropriate function definition for a given item. An obvious 
possibility were to bind function declarations to an item 
type which must be matched by the item on which the function 
is invoked, for example thus:
   declare itemFunction element(tringle) local:rotate() {...}
   declare itemFunction element(square, squareType) 
local:rotate() {...}

</div><div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">More flexibility is gained by the additional possibility to 
specify an item test in the form of an XPath expression:
   declare itemFunction element(), itemTest="@geometrical eq true()" 
               element(tringle, triangleType) local:rotate() {...}

</div><div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">To demonstrate the simplicity to be gained, imagine the task 
to edit a sequence of reports for rendering purposes. You might write
   $reports/.->render()

</div><div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">and start with a default implementation of the itemFunction 
'render'. Later, you refine the rendering by simply *adding* 
special versions, and you can even do so by just importing 
additional modules.

</div><div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">My questions to you:
- would such extensions of XQuery be desirable (from the 
user's point of view)
- would such extensions introduce drawbacks or problems (from 
the implementor's point of view)

</div><div class="footer signature" style="font-family: Arial, Helvetica, 'Luxi Sans', sans-serif; font-style: italic; white-space: pre; "><div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Thank you for any comments!
Hans-Juergen Rennau

</div></div><div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">_______________________________________________
<span>ta<a class="email" style="color: rgb(0, 0, 153); text-decoration: underline; font-size: 0.9em; cursor: pointer; ">...</a>@x-query.com</span>
<a class="exlink" href="http://x-query.com/mailman/listinfo/talk" rel="nofollow" style="color: rgb(0, 0, 153); text-decoration: underline; font-size: 0.9em; cursor: pointer; ">http://x-query.com/mailman/listinfo/talk</a>
</div></div><div class="footer noise" style="font-family: Arial, Helvetica, 'Luxi Sans', sans-serif; font-style: italic; white-space: pre; "><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">
</p></div><div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">_______________________________________________
<span>ta<a class="email" style="color: rgb(0, 0, 153); text-decoration: underline; font-size: 0.9em; cursor: pointer; ">...</a>@x-query.com</span>
<a class="exlink" href="http://x-query.com/mailman/listinfo/talk" rel="nofollow" style="color: rgb(0, 0, 153); text-decoration: underline; font-size: 0.9em; cursor: pointer; ">http://x-query.com/mailman/listinfo/talk</a></div></span></div><div><span class="Apple-style-span" style="font-family: Arial; font-size: 14px; white-space: pre; "></span></div></body></html>