Re: QT4CG meeting 145 draft agenda, 9 December 2025

> But what
> if I could write something like,
> 
> let $g := generator:new( {
>  “current” : $doc/dictionary/letter-group[1]/entry[1]/title ,
>  “next” : fn() { 
>    generator:new(
>      “current” :  $g/../following::entry[1]/title.
>      “next” : $g(“next”) (: copy the next function :)
> } )
> return process-books-by($g)
> 
> where process-books-by() is a function that processes $g→current() and
> then calls itself with $g→next() each time?
> 



I can write this in XQuery as

declare function next-book ($book) {$book//following-entry[1]/title};
declare function process-books($book) {
    do-something-with($book),
    next-book($book) =!> process-books()
};
process-books($doc/dictionary/letter-group[1]/entry[1]/title)

It seems from your description that process-books-by() still needs to call itself, so you haven't saved the user from the perils of recursion.

We could also provide a much simpler generator function:

fn:generate($iniitial-state, $step)

that returns a sequence of states where each state is derived from the previous state by applying the $step function, and you could then do

for $book in generate($doc/dictionary/letter-group[1]/entry[1]/title,
                                   fn($book) {$book//following-entry[1]/title}) 
return process-book($book)

I'm having great trouble seeing how the 42 new functions make my life easier.

Michael Kay

Received on Tuesday, 9 December 2025 10:04:38 UTC