-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
554/754 Simplify the new transitive-closure function #761
554/754 Simplify the new transitive-closure function #761
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for simplifying the function signature and removing min/max. It’s much easier now to understand what the function does, and I agree that it should be up to the user to avoid nondeterministic behavior.
@@ -18349,10 +18349,9 @@ return sort($in, $SWEDISH)</eg> | |||
|
|||
<fos:function name="transitive-closure" prefix="fn"> | |||
<fos:signatures> | |||
<fos:proto name="transitive-closure" return-type="function(node()) as node()*"> | |||
<fos:proto name="transitive-closure" return-type="node()*"> | |||
<fos:arg name="start" type="node()?"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that naming the parameter $node
would be more consistent with the remaining spec. It seems obvious enough that it will be the node from which the operation starts. Next, it would be a helpful hint, as transitive closures could potentially be computed from data structures other than nodes.
is unbounded. In this situation the function <var>TC</var> continues execution until no further nodes | ||
are added to the result set. Note that if the <code>$step</code> function constructs new nodes, this | ||
can lead to non-termination. Specifying an explicit value for <code>$max</code> guarantees termination.</p> | ||
<eg><![CDATA[declare %private function tc-inclusive( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve sllightly tweaked the formatting (and proactively renamed $start
to $node
):
declare %private function tc-inclusive(
$nodes as node()*,
$step as function(node()) as node()*
) as node()* {
let $nextStep := $nodes/$step(.)
let $newNodes := $nextStep except $nodes
return if (exists($newNodes))
then $nodes | tc-inclusive($newNodes, $step)
else $nodes
};
declare function transitive-closure(
$node as node(),
$step as function(node()) as node()*
) as node()* {
tc-inclusive($node/$step(.), $step)
};
<fos:expression><eg>let $tc := transitive-closure($direct-reports) | ||
return $tc($data//person[@id="2"])/string(@id)</eg></fos:expression> | ||
<fos:expression><eg>transitive-closure( | ||
$data//person[@id="2"]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$data//person[@id="2"]), | |
$data//person[@id="2"], |
return $tc($data//person[@id="2"])/string(@id)</eg></fos:expression> | ||
<fos:expression><eg>transitive-closure( | ||
$data//person[@id="2"]), | ||
$direct-reports)/string(@id)</eg></fos:expression> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$direct-reports)/string(@id)</eg></fos:expression> | |
$direct-reports | |
)/string(@id)</eg></fos:expression> |
@@ -18441,12 +18453,6 @@ return $tc($data)/@id/string()</eg></fos:expression> | |||
return $tc($root) =!> document-uri()</eg> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last example needs to be updated to match the new function signature:
transitive-closure($root, fn { document(//(xsl:import|xsl:include)/@href) })
=!> document-uri()
@michaelhkay Apart from the minor adjustments, I would approve the PR. |
7ce3c03
to
2530ac7
Compare
The group agreed to merge this PR at meeting 054 |
Drops the
$min
and$max
parameters, with the effect that this corresponds much more closely to the general computer-science definition of a transitive closure.The function now computes the set of nodes delivered by the transitive closure of the supplied
$step
function when applied to a given$start
node, rather than returning a function item that must then be applied to the chosen $start node. This is hopefully easier for most users to understand, and does not lose any useful functionality.The
$min
parameter of the old function is effectively forced to its default value of 1, and the $max value to its default of infinity.Fix #754
Fix #554
This PR addresses the main points of #554 in making the function correspond more closely to the mathematical (or at least the computer-science) definition of transitive closure. It doesn't implement other ideas in #554, like returning the depth of search alongside the actual closure. That's because I believe in the principle that wherever possible a function should do one thing in as simple a way as possible.