eXist version: Stable 1.4 (Eindhoven)
We were writing a MIN function for arbitrary values, since we need the minimum of a series of dates and the built-in min() function doesn't handle this type. While writing our (recursive) function, we noticed invalid output.
In particular, the value returned by $sequence seem to be inconsistent. However, this situation can be resolved by adding an UNREFERENCED let statement before the expression. See the attached file for an example.
The min1 function assigns the value of $sequence to a variable called $head, although this variable is never referenced. This function produces the right answer.
In the min2 function, the unused assignment is removed. This function produces the answer '2' instead of the correct answer '1'.