派生函数中的 last()

last() in spawned functions

为什么 fn:last() 功能在生成时不起作用?

这失败了:

xquery version "1.0-ml";
let $items := (1, 2, 3)
return xdmp:spawn-function(function () {
   $items[3 to fn:last()] 
}) 

一段时间后我取消了作业,因为它什么都不做。

Output: Cancelling fails with message indication function must be stopped manually.

这很好用:

xquery version "1.0-ml";
let $items := (1, 2, 3)[3 to fn:last()] 
return xdmp:spawn-function(function () {
   $items
}) 

Output: Query completed successfully

fn:last() is showing a very similar usage of this function. The downside for using functions in predicates is though that they are evaluated for each item in the sequence. Using fn:subsequence and optionally fn:count 文档的示例应该更有效,并且绕过您的问题:

let $items := (1, 2, 3)
return xdmp:spawn-function(function () {
   xdmp:log(subsequence($items, 3, count($items))) (: you can omit 3rd param with same effect :)
})

HTH!