[racket] Generics: implemented methods not inherited?
Is there a way to inherit methods from a parent struct?
If I'm not mistaken, it's not what #:defaults and other keywords are for.
For example, the following fails:
#lang racket
(require racket/generic)
(define-generics g
(foo g)
(bar g))
(struct a ()
#:methods gen:g
[(define (foo g) '(foo a))
(define (bar g) '(bar a))])
(struct b a ()
#:methods gen:g
[(define (foo g) '(foo b))])
(foo (a)) ; '(foo a)
(foo (b)) ; '(foo b)
(bar (a)) ; '(bar a)
(bar (b)) ; Error: bar: not implemented for #<b>
Laurent
On Fri, Sep 6, 2013 at 4:13 PM, Konrad Hinsen <konrad.hinsen at fastmail.net>wrote:
> Asumu Takikawa writes:
>
> > 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.
>
> That looks so obvious once you see it... Thanks a lot!
>
> Konrad.
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130906/aefe41fd/attachment.html>