In Python, using the first “truthy” value of several candidates can be written in the form:
result = a or b or c
…which avoids any need for repetition or variable assignment when dealing with result of function calls:
result = get-candidate() or get-default()
Is a terse, performant, readable equivalent available in XQuery?
The best I can come up with (without relying on the engine to optimize multiple calls to get-candidate() down to one, which may not be possible at all if it does something like an external HTTP or SQL transaction) is something akin to the following:
let $a := get-candidate()
return if($a) then $a else get-default()
…particularly if this is being repeated a number of times, it’s not very pretty.
What’s the best terse, readable approach?
If your candidate will either be a single item or an empty sequence, you can use the following notation:
(get-candidate(), get-default())[1]
Otherwise, you’ll probably have to stick with the verbose representation.