<div dir="ltr"><div><div><div><div>That doesn't sound right to me.<br></div>In the second clause, there already is a `print` method from some superclass, and this `print` method quite probably has a purpose, possibly not related to `printable<%>`, and you may not know what it is for.<br>

</div>But here this behavior is completely overridden for `printable<%>`, which means that if the method is used for its original purpose (which you may not be able to control, e.g., on instantiation) the program may crash.<br>

</div><div>If you do have control on what this original `print` is, then probably it should be renamed to avoid name collision.<br></div><div><br></div>Here I think the correct behavior is to throw an error saying that the class cannot be made `printable<%>` (or maybe implement an `printable2<%>`, but that too looks like bad duct tape).<br>

<br></div><div>Laurent<br></div><div><div><div><div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, May 24, 2014 at 3:16 PM, Roman Klochkov <span dir="ltr"><<a href="mailto:kalimehtar@mail.ru" target="_blank">kalimehtar@mail.ru</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>Ok, so <br><br>(define (printable %)<br>   (cond<br>     [(implementation % printable<%>) %] ;; already have<br>     [(method-in-interface? 'print (class->interface %)) ;; have another print, should override<br>

      ((mixin () (printable<%>) (define/override (print) (displayln this))) %)<br>     [else ;; no method, add<br>       ((mixin () (printable<%>) (define/public (print) (displayln this))) %)))<br><br>Without second clause (method-in-interface? ....), I cannont make an implemetation of printable<%> with given superclass.<br>

<br><br>Sat, 24 May 2014 12:22:20 +0200 от Laurent <<a href="mailto:laurent.orseau@gmail.com" target="_blank">laurent.orseau@gmail.com</a>>:<div class=""><br>
<blockquote style="margin:10px;padding:0px 0px 0px 10px;border-left-color:rgb(8,87,166);border-left-width:1px;border-left-style:solid">
        <div>
        



    









        
        


        
        
        
        
        

        
        

        
        



<div>
        
        <div>
                
                
                        <div><div dir="ltr"><div><div><div> </div><blockquote style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><div>Another example is a mixin. Suppose I have an interface printable<%> = (interface () print)) and I want to make a mixin printable, that should make any class to implement printable.<br>



The only solution is:<br><br>(define (printable %)<br>   (if (method-in-interface? 'print (class->interface %))<br>       %<br>       ((mixin () (print) (define (print) (displayln this))) %)))<br></div></blockquote>



<div><br></div><div>Here too, and the new class should implement `printable<%>` instead of just implementing the method.<br></div><div>Then to know if you can call `print` on a given object, you should first check that it implements `printable`.<br>



<br></div>Checking for the implementation of the right interface ensures that the method does what you think it should do; because maybe someone has defined another interface `my-printable<%>` that also declares `print` but has a quite different purpose from `printable<%>`.<br>



<div></div><div><br></div><div>Maybe I'm  totally missing something here, but the only correct use I see to `method-in-interface?` is in Racket's implementation of the class system, to check for errors if the method is called but may not exist.</div>



</div><br></div><div>Laurent<br></div></div>

</div>
                        
                
                
        </div>

        
</div>


</div>
</blockquote>
<br>
<br></div><span class="HOEnZb"><font color="#888888">-- <br>Roman Klochkov<br></font></span></div>
</blockquote></div><br></div></div></div></div></div></div></div></div>