[xquery-talk] tail recursive identity transformation

Kendall Shaw kshaw at kendallshaw.com
Fri Sep 15 01:30:46 PDT 2017

I don't remember seeing an xquery function that tries to return it's 
input unchanged.

Can this be improved:

declare function local:id($e as element()?, $acc as element()?) as 
element() {
   if (empty($e)) then
             , element {node-name($e)} {
               , for $node in $e/node()
                 return typeswitch($node)
                          case element() return local:id($node, $acc)
                          default return $node

The idea is that functions that do more than return their input could be 
based on the function, and benefit from tail call optimization.


More information about the talk mailing list