Re: [Scheme-reports] Seeking review of sets and hash tables proposals
John Cowan 26 May 2013 12:28 UTC
Ray Dillinger scripsit:
> I think user-supplied ordering functions are a relatively easy
> requirement for most users to fulfil, but hash functions that work as
> hash functions while mapping 'equal' things under a custom predicate
> to equivalent buckets are surprisingly subtle. Requiring the user
> to supply one would make the library unfriendly to use and perhaps
> impossible in some cases.
That's why an implementation is required to handle `eq?`, `eqv?`,
`equal?`, `string=?`, and `string-ci=?` equivalence predicates by
supplying its own hash function for them. But if you want to use a
predicate coarser than `equal?` (other than the last of these), you simply
have no choice but to supply a hash function to go with it, because of
the requirement that if two objects are equivalent, their hashes are `=`.
The only alternative is to do what many Schemes as well as Common Lisp
do, and *only* support the set of five fixed equivalence predicates.
In that case, the user never need deal with hash functions at all,
but it becomes impossible to deal with records as keys, because of the
indeterminacy of `equal?` around them.
So far I haven't heard about any *actual* cases of people requiring
specialized equivalence predicates, though it's easy to make up
hypotheticals.
--
John Cowan http://www.ccil.org/~cowan cowan@ccil.org
Please leave your values Check your assumptions. In fact,
at the front desk. check your assumptions at the door.
--sign in Paris hotel --Cordelia Vorkosigan
_______________________________________________
Scheme-reports mailing list
Scheme-reports@scheme-reports.org
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports