Clarification on hof:until

Friday, 16 June 2017 · 2 messages
ML
Marco Lettere16 Jun 2017 15:55 #
Dear Basex team, today I was trying out hof:until with the code [1]. According to the documentation [2] it should behave like a sort of "do code until condition" and I'd expect it to return 1 but I get 0 instead thus it rather seems like a "until condition do code". Are my expectations wrong? Thanks, Marco. [1]
declare function local:pred($res){ true() };
declare function local:loop($val){ $val + 1 };

hof:until(local:pred#1, local:loop#1, 0)

[2] Applies the function|$f|to the initial value|$start|until the
predicate|$pred|applied to the result returns|true()|.
CG
Christian Grün16 Jun 2017 17:22 #
Hi Marco,
Quoted text · Marco Lettere · 3 lines
> According to the documentation [2] it should behave like a sort of "do code > until condition" and I'd expect it to return 1 but I get 0 instead thus it > rather seems like a "until condition do code".
The best wording is probably subject to discussion. Indeed the execution will stopped if the predicate function yields true, and (as you say) the first check occurs before the first execution [1]. I’ll be happy to rewrite the documentation (or I’ll even be happier if someone else wants to do it ;). Cheers, Christian [1] https://github.com/BaseXdb/basex/blob/master/basex-core/src/main/java/org/basex/query/func/hof/HofUntil.java

⚡Generated with XQuery