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

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


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)))
    ((eqv? equiv? eq?)
    ((eqv? equiv? eqv?)
     (make-hashtable equiv?))))

Code like this actually appears in the R6RS implementation of SRFI 69 at
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