SRFI 146: comparator equality and a test in sample implementation Sudarshan S Chawathe (23 Mar 2020 17:29 UTC)
Re: SRFI 146: comparator equality and a test in sample implementation Marc Nieper-Wißkirchen (25 Mar 2020 08:57 UTC)

SRFI 146: comparator equality and a test in sample implementation Sudarshan S Chawathe 23 Mar 2020 17:29 UTC

One of the tests included in the SRFI 146 sample implementation (line
364 of test.sld, excerpted below) seems to imply required inequality of
two comparators (and thus mappings with those) that have the same four
component procedures (type test, equality, ordering, hash).  I may be
missing something obvious but I cannot find that requirement in either
SRFI 146 or SRFI 128.

Further, a quick check with Chibi Scheme seems to support the
possibility of such comparators being equal:

  (import (scheme base)
          (scheme write)
          (srfi 128))

  (write
   (let ((c (make-default-comparator)))
     (list (equal? c c)
           (equal? c (make-comparator (comparator-type-test-predicate c)
                                      (comparator-equality-predicate c)
                                      (comparator-ordering-predicate c)
                                      (comparator-hash-function c))))))
  (newline)

prints:

  (#t #t)

which makes sense to me, but seems to contradict the above-mentioned
test.

I would be grateful if someone can clarify the situation.

Here is the test in question, for easy reference:

  (test-group "Submappings"
    (define mapping1 (mapping comparator 'a 1 'b 2 'c 3))
    (define mapping2 (mapping comparator 'a 1 'b 2 'c 3))
    (define mapping3 (mapping comparator 'a 1 'c 3))
    (define mapping4 (mapping comparator 'a 1 'c 3 'd 4))
    (define mapping5 (mapping comparator 'a 1 'b 2 'c 6))
    (define mapping6 (mapping (make-comparator (comparator-type-test-predicate comparator)
                                               (comparator-equality-predicate comparator)
                                               (comparator-ordering-predicate comparator)
                                               (comparator-hash-function comparator))
                              'a 1 'b 2 'c 3))

    ;; other tests omitted

    (test-assert "mapping=?: different comparators"
      (not (mapping=? comparator mapping1 mapping6)))

    ;; other tests omitted

    )

Regards,

-chaw