<div dir="ltr"><div><div>Is there a way to inherit methods from a parent struct?<br></div><div>If I'm not mistaken, it's not what #:defaults and other keywords are for.<br></div><br></div>For example, the following fails:<br>
<div><br>#lang racket<br>(require racket/generic)<br>(define-generics g<br> (foo g)<br> (bar g))<br><br>(struct a ()<br> #:methods gen:g<br> [(define (foo g) '(foo a))<br> (define (bar g) '(bar a))])<br><br>
(struct b a ()<br> #:methods gen:g<br> [(define (foo g) '(foo b))])<br><br>(foo (a)) ; '(foo a)<br>(foo (b)) ; '(foo b)<br>(bar (a)) ; '(bar a)<br>(bar (b)) ; Error: bar: not implemented for #<b><br>
<br><br>Laurent<br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Sep 6, 2013 at 4:13 PM, Konrad Hinsen <span dir="ltr"><<a href="mailto:konrad.hinsen@fastmail.net" target="_blank">konrad.hinsen@fastmail.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">Asumu Takikawa writes:<br>
<br>
> You can write the method implementations as plain function definitions<br>
> in some module, e.g.,<br>
><br>
> (define (my-dict-ref ...) ...)<br>
> ...<br>
> (provide my-dict-ref ...)<br>
><br>
> and then in each structure you can do<br>
><br>
> (struct particular-dict (...)<br>
> #:methods<br>
> [(define dict-ref my-dict-ref)<br>
> ...])<br>
><br>
> to share the implementations.<br>
<br>
</div>That looks so obvious once you see it... Thanks a lot!<br>
<span class="HOEnZb"><font color="#888888"><br>
Konrad.<br>
</font></span><div class="HOEnZb"><div class="h5">____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</div></div></blockquote></div><br></div></div></div>