Hi Christian,
That hof:until update recipe is very helpful.
From my occasional reads of qt4 feeds, I guess Graydon's function might
look something like the below I like the look of the upcoming V4.0 features.
/Andy
declare function local:dropTableLinesFancy($in as node()*) as node()* { do-until( (: initial input = we start with no new nodes :) map { 'oldNodes': $in, 'newNodes': (), 'toggle': false() }, fn($m){ map { 'oldNodes': tail($m?oldNodes), 'newNodes': ($m?newNodes, switch { case starts-with(head($m?oldNodes),':stab') return <line/> case starts-with(head($m?oldNodes),':rtab') return <line/> case $m?toggle return <line/> default return head($m?oldNodes) }), 'toggle': switch { case starts-with(head($m?oldNodes),':stab') return true() case starts-with(head($m?oldNodes),':rtab') return false() default return $m?toggle } } }, (: are we done? (= we've run off the end of our list of nodes ) :) fn($m){ empty($m?oldNodes) } )?newNodes };
On Thu, 28 Mar 2024 at 18:34, Christian Grün christian.gruen@gmail.com wrote:
Hi Graydon,
Folks tell us it’s time to stop delaying BaseX 11… We’re trying hard.
The good news: The only difference between hof:until [1] and fn:do-until [2] is the order of parameters. The following queries will do the same thing:
hof:until(function($a) { $a > 16 }, function($a) { $a * 2 }, 1) do-until(1, function($a) { $a * 2 }, function($a) { $a > 16 })
With fn:do-until, the input has moved to the first position, the action comes second and the predicate comes last.
Hope this helps, Christian
[1] https://files.basex.org/releases/10.0/BaseX100.pdf [2] https://qt4cg.org/specifications/xpath-functions-40/Overview.html#func-do-un...
On Thu, Mar 28, 2024 at 5:41 PM Graydon graydonish@gmail.com wrote:
Hi Andy --
On Thu, Mar 28, 2024 at 01:06:10PM +0000, Andy Bunce scripsit:
hof:until is not gone, it is just hiding [1]
- In 10.7 it is there but undocumented in Wiki
Which is useful to know -- thank you! -- but makes me think a bunch of my production code is going to break hard when 11 is released. I would really like to avoid that. (In particular, the conversation with management about how much refactoring work will be required.)
- In BaseX 11 you need to use XQuery 4 fn:while-do⁺, fn:do-until⁺ [2]
It is very probably my brain, but I'm having trouble transposing hof:until to those functions. I can an implement what I want to do with hof:until like so:
declare function xc:dropTableLinesFancy($in as node()*) as node()* { let $result as map(*) := hof:until( (: are we done? (= we've run off the end of our list of nodes ) :) function($m) { empty($m?oldNodes) }, (: create new list of line elements :) function($m) { map { 'oldNodes': tail($m?oldNodes), 'newNodes': ($m?newNodes, switch (true()) case starts-with(head($m?oldNodes),':stab') return <line/> case starts-with(head($m?oldNodes),':rtab') return <line/> case $m?toggle return <line/> default return head($m?oldNodes) ), 'toggle': ( switch (true()) case starts-with(head($m?oldNodes),':stab') return true() case starts-with(head($m?oldNodes),':rtab') return false() default return $m?toggle ) } }, (: initial input = we start with no new nodes :) map { 'oldNodes': $in, 'newNodes': (), 'toggle': false() } ) return $result?newNodes };
Anyone willing to provide an example of what that would look like in fn:while-do or fn:do-until?
Thanks! Graydon
-- Graydon Saunders | graydonish@fastmail.com Þæs oferéode, ðisses swá mæg. -- Deor ("That passed, so may this.")