On this page:
make-accessor-based-equal+  hash
4.1 Struct Equality and Hashing
make-struct-equal+  hash
4.2 Tuple Equality and Hashing
make-tuple-equal+  hash
7.3

4 Equality and Hashing Implementations

 (require rebellion/equal+hash) package: rebellion

procedure

(make-accessor-based-equal+hash accessor 
  size) 
  (list/c procedure? procedure? procedure?)
  accessor : (-> any/c natural? any/c)
  size : natural?
Builds an equality-checking function, a hashing function, and a secondary hashing function suitable for use with prop:equal+hash. These functions extract size fields from values using accessor and recursively compare and hash them. This function is typically not used directly; instead clients are expected to use one of make-struct-equal+hash or make-tuple-equal+hash.

4.1 Struct Equality and Hashing

 (require rebellion/equal+hash/struct)
  package: rebellion

procedure

(make-struct-equal+hash descriptor)

  (list/c procedure? procedure? procedure?)
  descriptor : struct-descriptor?
Builds an equality-checking function, a hashing function, and a secondary hashing function suitable for use with prop:equal+hash, each of which operate on instances of descriptor. All fields in descriptor are compared and hashed by the returned procedures. This causes equal? to behave roughly the same as it does on transparent structure types.

Examples:
> (struct opaque-point (x y))
> (equal? (opaque-point 1 2) (opaque-point 1 2))

#f

> (define point-descriptor
    (make-struct-type/descriptor
     #:name 'point
     #:immutable-fields 2
     #:property-maker
     (λ (descriptor)
       (define equal+hash (make-struct-equal+hash descriptor))
       (list (cons prop:equal+hash equal+hash)))))
> (define point (struct-descriptor-constructor point-descriptor))
> (equal? (point 1 2) (point 1 2))

#t

4.2 Tuple Equality and Hashing

 (require rebellion/equal+hash/tuple) package: rebellion

procedure

(make-tuple-equal+hash descriptor)

  (list/c procedure? procedure? procedure?)
  descriptor : tuple-descriptor?
Builds an equality-checking function, a hashing function, and a secondary hashing function suitable for use with prop:equal+hash, each of which operate on instances of descriptor. All fields in descriptor are compared and hashed by the returned procedures. This causes equal? to behave roughly the same as it does on transparent structure types.

Examples:
> (define-tuple-type point (x y)
    #:property-maker
    (λ (descriptor)
      (list (cons prop:equal+hash (make-tuple-equal+hash descriptor)))))
> (equal? (point 1 2) (point 1 2))

#t

> (equal? (point 1 2) (point 2 1))

#f