[racket] Implementing an generic interface outside of a struct definition
On 2013-09-06 15:46:20 +0200, Konrad Hinsen wrote:
> The reason for wanting to implement the methods separately is plain
> economy: I have five structures that can use a strictly identical
> implementation for gen:dict, and I want to write the code only once.
You can write the method implementations as plain function definitions
in some module, e.g.,
(define (my-dict-ref ...) ...)
...
(provide my-dict-ref ...)
and then in each structure you can do
(struct particular-dict (...)
#:methods
[(define dict-ref my-dict-ref)
...])
to share the implementations.
Cheers,
Asumu