Hello Leo --
On Sat, Jun 05, 2021 at 12:35:33AM +0200, Leonard Wörteler scripsit: [snip]
In BaseX tail calls can be inside (at least) nested layers of the `then` and `else` branches of `if`, the results of a `switch` or `typeswitch` and in the `return` of a FLWOR expression in which each clause is statically known to produce either 0 or 1 result/binding.
[snip]
Hope that helps!
It does help, thank you!
It needs a tweak to do the thing -- $after always sheds the head of the sequence, $before does only when there's a match. Otherwise if the processing adds a sentence, the alignment for an appropriate compare is lost for every subsequent attempted match.
And the devil crept up behind me and whispered "compactness", so I wound up with:
declare function local:subtractSentences( $before as xs:string*, $after as xs:string*, $out as xs:string* ) as xs:string* { let $thisBefore as xs:string? := head($before) let $thisAfter as xs:string? := head($after)
let $matches as xs:boolean := ends-with($thisAfter,$thisBefore)
return if (empty($thisBefore) or empty($thisAfter)) then ($out, $after) else local:subtractSentences( if ($matches) then tail($before) else $before, tail($after), ($out,if (not($matches)) then $thisAfter else replace($thisAfter,$thisBefore,'','q')) ) };
This is about twice as fast -- twenty-odd milliseconds instead of thereabouts of fifty -- compared to the messing-with-indexes version.
Not going to try to decide which I think is more clearly expressive at this hour.
Thank you! Graydon