[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Scheme-reports] Procedure equivalence: the last debate



[+r6rs-discuss]

It occurs to me that because of the R6RS procedure equivalence rules,
it's impossible to efficiently implement something like `hashtable-map`
(which lifts a function to the domain of hash tables) while being
strictly conformant.  To do so, one must be able to create a hash
table with the same equality procedure and hash function as a given
hash table.  The `hashtable-copy` function does this, but it also copies
the associations, which is not wanted in this case.

However, in order to create a most-efficient hash table whose equality
predicate is `eq(v)?`, you need to invoke `make-eq(v)-hashtable` rather
than the general `make-hashtable`.  But although it is possible to
retrieve the equality predicate using `hashtable-equivalence-function`,
and although R6RS guarantees that this procedure returns `eq(v)?`
in the relevant cases, you cannot test whether that is what you have!
The following code fragment is not portable:

(let ((equiv? (hashtable-equivalence-function some-hash-table)))
  (cond
    ((eqv? equiv? eq?)
     (make-hashtable-eq))
    ((eqv? equiv? eqv?)
     (make-hashtable-eqv))
    (else
     (make-hashtable equiv?))))

Code like this actually appears in the R6RS implementation of SRFI 69 at
<https://code.launchpad.net/~scheme-libraries-team/scheme-libraries/srfi>,
which suggests that in fact none of the R6RS implementations are making
use of this optimization, at least in this kind of case.

-- 
Only do what only you can do.               John Cowan <cowan@x>
  --Edsger W. Dijkstra's advice
    to a student in search of a thesis

_______________________________________________
Scheme-reports mailing list
Scheme-reports@x
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports