Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Who uses SRFI 69 or R6RS hash tables with arbitrary hash functions?

98 views
Skip to first unread message

John Cowan

unread,
May 22, 2013, 11:05:19 PM5/22/13
to
I'd like to hear from Schemers who make use of hash tables, either the SRFI 69 or the R6RS flavor, that need to go beyond the classic five equivalence predicates, namely `eq?`, `eqv?`, `equal?`, `string=?`, and `string-ci=?`. When do you use them? What equivalence predicates do you use? What hash functions accompany them?

Note that in SRFI 69, you can use the `hash` hash procedure for `eqv?` as well as `equal?` hash tables, and in R6RS, you can use the `equal-hash` hash procedure for `string=?` as well as `equal?`.

Jussi Piitulainen

unread,
May 23, 2013, 3:12:48 AM5/23/13
to
John Cowan writes:

> I'd like to hear from Schemers who make use of hash tables, either
> the SRFI 69 or the R6RS flavor, that need to go beyond the classic
> five equivalence predicates, namely `eq?`, `eqv?`, `equal?`,
> `string=?`, and `string-ci=?`. When do you use them? What
> equivalence predicates do you use? What hash functions accompany
> them?

These are mere thoughts, not the actual usage data you are asking, but
anyway:

Record types. R7RS Draft 9 entry on equal? says nothing about the
equality of records.

Also, one might use procedures as a kind of object, wanting some sort
of structural equality. They will be opaque to equal? even when the
eqv? issue is sorted out.

Perhaps structured objects might have components that should not be
involved in their equality and hashing: components with state, or
components whose equality is not specified.

But mainly record types. It would be quite unschemely to have sets of
pairs, lists, vectors, bytevectors, and then not sets of records.

> Note that in SRFI 69, you can use the `hash` hash procedure for
> `eqv?` as well as `equal?` hash tables, and in R6RS, you can use the
> `equal-hash` hash procedure for `string=?` as well as `equal?`.

--

Ludovic Courtès

unread,
May 23, 2013, 8:21:06 AM5/23/13
to
Jussi Piitulainen <jpii...@ling.helsinki.fi> skribis:

> Perhaps structured objects might have components that should not be
> involved in their equality and hashing: components with state, or
> components whose equality is not specified.

Yes, that happened to me (using Guile’s hash table API, which is similar
to SRFI-69).

Ludo’.

Daniel Villeneuve

unread,
May 23, 2013, 9:20:29 PM5/23/13
to
Same situation for me: hashing structured objects with internal mutable
state.

;; a.b is a pair of two complex objects with mutable state, of which
;; the "identifier" (a symbol) obtained from get-id is sufficient for
;; comparison purposes
(define (my-hash a.b)
(hash-equal (cons (get-id (car a.b))
(get-id (cdr a.b)))))

;; note: comparing actual objects, not their ids here
(define (my-equal? a1.b1 a2.b2)
(and (eq? (car a1.b1) (car a2.b2))
(eq? (cdr a1.b1) (cdr a2.b2))))

I've not seen that used often in our code base, but I found it nice to
have the general interface available.
--
Daniel Villeneuve

0 new messages