Skip to content

Commit

Permalink
Merge pull request #978 from dnovatchev/master
Browse files Browse the repository at this point in the history
948 Reflected the comments of the CG on the specification of scan-left and scan-right
  • Loading branch information
ndw authored Feb 13, 2024
2 parents 3d40a75 + 93df338 commit c3dbed0
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions specifications/xpath-functions-40/src/function-catalog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29947,7 +29947,7 @@ path with an explicit <code>file:</code> scheme.</p>
<fos:proto name="scan-left" return-type="array(*)*">
<fos:arg name="input" type="item()*" usage ="navigation"/>
<fos:arg name="zero" type="item()*"/>
<fos:arg name="action" type="function(item()*, item()*) as item()*" usage="inspection"/>
<fos:arg name="action" type="function(item()*, item()) as item()*" usage="inspection"/>
</fos:proto>
</fos:signatures>
<fos:properties>
Expand All @@ -29960,33 +29960,34 @@ path with an explicit <code>file:</code> scheme.</p>
the accumulator is assigned to during the evaluation of fn:fold-left.</p>
</fos:summary>
<fos:rules>
<p>The function is equivalent to the following implementation in XPath(return clause added for completeness):</p>
<p>The function is equivalent to the following implementation in XPath (return clause added in comments for completeness):</p>
<eg><![CDATA[
let $scan-left-inner := function($seq as item()*,
let $scan-left-inner := function($input as item()*,
$zero as item()*,
$fun as function(item()*, item()*) as item()*,
$action as function(item()*, item()) as item()*,
$self as function(*)
) as array(*)*
{
let $result := [$zero]
return
if(empty($seq)) then $result
if(empty($input)) then $result
else
(
$result, $self(tail($seq), $fun($zero, head($seq)), $fun, $self)
$result, $self(tail($input), $action($zero, head($input)), $action, $self)
)
},

$scan-left := function($seq as item()*,
$scan-left := function($input as item()*,
$zero as item()*,
$fun as function(item()*, item()*) as item()*
$action as function(item()*, item()) as item()*
) as array(*)*
{
$scan-left-inner($seq, $zero, $fun, $scan-left-inner)
$scan-left-inner($input, $zero, $action, $scan-left-inner)
}

(:
return
$scan-left(1 to 10, 0, op('+'))
$scan-left(1 to 10, 0, op('+'))
:)
]]></eg>
</fos:rules>
<fos:errors>
Expand Down Expand Up @@ -30026,7 +30027,7 @@ $scan-left := function($seq as item()*,
without losing completely the intermediate results.</p>
<fos:test>
<fos:expression><eg>let $double := fn($x){2 * $x}
return $scan-left(1 to 5, (), fn($seq, $it){$seq , $double($it)})</eg></fos:expression>
return scan-left(1 to 5, (), fn($seq, $it){$seq , $double($it)})</eg></fos:expression>
<fos:result>[()], [2], [(2,4)], [(2,4,6)], [(2,4,6,8)], [(2,4,6,8,10)]</fos:result>
</fos:test>
</fos:example>
Expand Down Expand Up @@ -30061,31 +30062,32 @@ $scan-left := function($seq as item()*,
the accumulator is assigned to during the evaluation of fn:fold-right.</p>
</fos:summary>
<fos:rules>
<p>The function is equivalent to the following implementation in XPath(return clause added for completeness):</p>
<p>The function is equivalent to the following implementation in XPath (return clause in comments added for completeness):</p>
<eg><![CDATA[
let $scan-right-inner := function($seq as item()*,
let $scan-right-inner := function($input as item()*,
$zero as item()*,
$f as function(item()*, item()*) as item()*,
$action as function(item()*, item()) as item()*,
$self as function(*)
) as array(*)*
{
if(empty($seq)) then [$zero]
if(empty($input)) then [$zero]
else
let $rightResult := $self(tail($seq), $zero, $f, $self)
let $rightResult := $self(tail($input), $zero, $action, $self)
return
([$f(head($seq), head($rightResult))], $rightResult)
([$action(head($input), head($rightResult))], $rightResult)
},

$scan-right := function($seq as item()*,
$scan-right := function($input as item()*,
$zero as item()*,
$f as function(item()*, item()*) as item()*
$f as function(item()*, item()) as item()*
) as array(*)*
{
$scan-right-inner($seq, $zero, $f, $scan-right-inner)
}

$scan-right-inner($input, $zero, $f, $scan-right-inner)
}
(:
return
$scan-right(1 to 10, 0, op('+'))
$scan-right(1 to 10, 0, op('+'))
:)
]]></eg>
</fos:rules>
<fos:errors>
Expand Down

0 comments on commit c3dbed0

Please sign in to comment.