Changes

Jump to navigation Jump to search
69 bytes removed ,  13:50, 12 December 2017
|-
| '''Summary'''
|Applies the predicate function {{Code|$pred}} to {{Code|$start}}. If the result is {{Code|false}}, applies the function {{Code|$f}} to is invoked with the start value and– or, subsequently, to with the result of this function until the predicate function returns {{Code|true()}}.
|-
| '''Examples'''
|
* {{Code|hof:Doubles a numeric value until(function($x) { $x ge 1000 }, function($y) { 2 * $y }, 1)}} returns {{Code|1024}}.* Calculating the square-root of a number by iteratively improving an initial guessmaximum is reached:
<pre class="brush:xquery">
hof:until( function($output) { $output ge 1000 }, function($input ) { 2 * $input }, 1)</pre>* Calculates the square-root of a number by iteratively improving an initial guess:<pre class="brush:xquery">let $sqrt := function($x input as xs:double) as xs:double {
hof:until(
function($resresult) { abs($res result * $res result - $xinput) < 0.00001 }, function($guess) { ($guess + $x input div $guess) div 2 }, $xinput
)
}
return $sqrt(25)
</pre>
returns * Returns {{Code|5.000000000053722OK}}. * The evaluation of , as the predicate is pre-fixed, thus every cycle starts with the evaluation of the predicate evaluated first.:
<pre class="brush:xquery">
declare hof:until( function local:pred($res_) { true() };,declare function local:loop($val_) { $val + 1 error() };, 'OK'hof:until(local:pred#1, local:loop#1, 0)
</pre>
returns {{Code|0}}.
 
|}
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu