function as default parameter
Saturday, 14 February 2026 · 2 messages
RS
Rob Stapper14 Feb 2026 09:57 #
Good morning,
I came across some unexpected behaviour when using a function as a default functionparameter:
declare function local:test
( $exec as function(*)? := fn( $a, $b) { $a => trace("test1: ") }
)
{ $exec( "a", "b")
} ;
local:test(())I would expect a trace- and a execution result, but I got nothing. Are my expectations wrong or could it be a bug?
PS code snipped added as test.xqm
PS The optimized query shows an empty value.
mvgr.
Rob Stapper
GR
Gunther Rademacher14 Feb 2026 10:34 #
Hi Rob,
this behaves as expected. The default for parameter $exec only applies, when you omit the argument, as in
local:test()But in your example, the function item is the empty sequence, so you are effectively doing
()("a", "b")
which by definition results in the empty sequence:
https://qt4cg.org/specifications/xquery-40/xquery-40.html#id-eval-dynamic-function-call
Best regards
Gunther
Gesendet: Samstag, 14. Februar 2026 um 09:57
Quoted text · Rob Stapper · 16 lines
Von: "Rob Stapper via BaseX-Talk" <basex-talk at mailman.uni-konstanz.de> An: "basex-talk at mailman.uni-konstanz.de" <basex-talk at mailman.uni-konstanz.de> Betreff: [basex-talk] function as default parameter Good morning, I came across some unexpected behaviour when using a function as a default functionparameter: declare function local:test ( $exec as function(*)? := fn( $a, $b) { $a => trace("test1: ") } ) { $exec( "a", "b") } ; local:test(()) I would expect a trace- and a execution result, but I got nothing. Are my expectations wrong or could it be a bug? PS code snipped added as test.xqm PS The optimized query shows an empty value. mvgr. Rob Stapper
Written for BaseX 12.2. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery