Hi Rob,
Thanks for the example. So you would like to have a function that returns a function item, which references the function in which it is currently evaluated?
* Original version:
declare function local:f($v) { if($v > 0) then local:f($v - 1) else "OK" }; local:f(3)
* Version with hof:self():
declare function local:f($v) { if($v > 0) then $v + hof:self($v - 1)($v) }; local:f(3)
I haven’t thought about all the implications yet, but I believe that the addition of such a function would restrict the way how we code can be optimized. Take this query for example:
declare function local:add($x, $y) { $x + $y }; local:add(1, 2)
The query optimizer will inline the called function and simplify the expression to
1 + 2
In the following query…
declare function local:add() { hof:self() }; local:add()
…we would need to suppress query inlining because it would otherwise yield different results.
Cheers, Christian