W3C home > Mailing lists > Public > public-qt-comments@w3.org > October 2007

[Bug 5183] [FO] Effect of type promotion in fn:distinct-values

From: <bugzilla@wiggum.w3.org>
Date: Tue, 16 Oct 2007 14:41:51 +0000
CC:
To: public-qt-comments@w3.org
Message-Id: <E1IhncF-0007Ft-8K@wiggum.w3.org>

http://www.w3.org/Bugs/Public/show_bug.cgi?id=5183





------- Comment #2 from mike@saxonica.com  2007-10-16 14:41 -------
This is a tricky problem. The rule I suggested in comment #1, of converting to
the least common supertype, suffers the disadvantage that when you process a
sequence in order, you cannot always tell whether a value is a "new value"
(distinct from all previous values) immediately.

I believe Saxon converts all numeric values to double unconditionally before
deciding whether the value is unique. That's not very satisfactory either. 

The only rule I can really think of is (a) take the sequence in some
implementation-defined order, (b) for each value, if the value is equal to some
previous value (that has been deemed distinct), discard it, otherwise include
it in the result of the function. The effect of this rule is that not only is
the order of the result implementation-defined (as now), but in pathological
cases different implementations may find a different number of distinct values.

I think that's effectively teh following, excluding pathologicals such as NaN:

declare function distinct-values($arg) {
  let $s := unordered($arg)
  return
    if (exists($s))
    then ($s[1], distinct-values(remove($s,1)[. ne $s[1]]))
    else ()
}
Received on Tuesday, 16 October 2007 14:42:09 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 16:57:20 UTC