Re: QT4CG-003-02: MK to propose a reformulation of fn:index-of() in terms of fn:index-where()

Michael Kay <mike@saxonica.com> writes:
> I considered defining the comparison of values using deep-equal(), but
> that gives the wrong result for NaN.
>
> I think it would be something like
>
> index-where($input, ->{$item){deep-equal($item, $search) and not (is-NaN($item)))
>
> but that requires careful checking.
>
> It's actually easier to do it the other way around: index-where($input, $predicate) can be expressed as
>
> index-of($input ! $predicate(.), true())

If the goal is to express one in terms of the other in order to reduce
some measure of complexity in the spec, I have more confidence in the
latter than the former. But that said, I had squint at it for 10 seconds
to persuade myself I understood what it said, so I’m not sure it’s going
to reduce the complexity for all readers.

> But it might be better to formulate index-where as
>
> for $item at $position in $input
> where $predicate($item)
> return $position

That seems clear to me. Is the suggestion that it should be normatively
described this way, or only that this should be shown as an illustration
of its semantics?

                                        Be seeing you,
                                          norm

--
Norm Tovey-Walsh
Saxonica

Received on Wednesday, 21 September 2022 06:54:32 UTC