Discussion:
[basex-talk] Clarification on hof:until
Marco Lettere
2017-06-16 13:55:40 UTC
Permalink
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()|.
Christian Grün
2017-06-16 15:22:42 UTC
Permalink
Hi Marco,
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
Loading...