racket-collections icon indicating copy to clipboard operation
racket-collections copied to clipboard

Improve documentation of gen:indexable

Open sam-d opened this issue 4 years ago • 0 comments

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

  1. Could you update the documentation with a small example?
  2. How is this choice motivated? It seems different to the rest of the generics

sam-d avatar Jun 11 '20 17:06 sam-d