racket-collections
racket-collections copied to clipboard
Improve documentation of gen:indexable
I had a hard time figuring out how to create a struct that implements gen:indexable
My attempt:
(struct ash (h) #:methods gen:indexable [(define (ref collection index) (hash-ref (ash-h collection) index)) (define (set-ref collection index value) (ash (hash-set (ash-h collection) index value)))]
With error message:
gen:indexable: generic method definition has an incorrect arity; expected a procedure that accepts 1 or more arguments ref: #<procedure:ref>
Asking for help on slack I realised the expected definition was (define (ref collection . rest) ...)
I have two questions
- Could you update the documentation with a small example?
- How is this choice motivated? It seems different to the rest of the generics