16 Structs
| (require scramble/struct) | package: scramble-lib |
value
:
(struct-type-property/c (or/c #t 'all (listof exact-nonnegative-integer?)))
In addition to the indicated fields, the hash code function also depends on a random seed and the name of the struct type. A new random seed is generated for each instantiation of the scramble/struct module.
If prop:auto-equal+hash is attached to a struct type that has a super struct type, then the super struct type must also have the prop:auto-equal+hash, and the new equality and hash code functions extend the super type’s functions. If the super struct type does not have the prop:auto-equal+hash property, an error is raised.
> (struct point (x y) #:property prop:auto-equal+hash #t) > (equal-hash-code (point 1 2)) 980885731491602527
> (equal? (point 1 2) (point 1 2)) #t
> (equal? (point 1 2) (point 0 0)) #f
In the following example, the equality and hash code functions of the point3 struct type use only the z field out of point3’s fields, disregarding the color field, but they also use both of point’s fields.
> (struct point3 point (z color) #:property prop:auto-equal+hash (list (struct-field-index z)))
> (equal? (point3 1 2 3 #f) (point3 1 2 3 'red)) #t
> (equal? (point3 0 0 3 'red) (point3 1 2 3 'red)) #f
> (equal? (equal-hash-code (point3 1 2 3 #f)) (equal-hash-code (point3 1 2 3 'red))) #t
value
:
(struct-type-property/c (or/c #t (listof exact-nonnegative-integer?)))
If prop:auto-custom-write is attached to a struct type that has a super struct type and if that super struct type also has the prop:auto-custom-write property, then the new printer includes the super-type’s fields.
> (struct point (x y) #:property prop:auto-custom-write #t) > (point 1 2) (point 1 2)
> (struct point3 point (z) #:property prop:auto-custom-write #t) > (point3 1 2 3) (point3 1 2 3)
Added in version 0.6 of package scramble-lib.