[racket] public, override -- how to combine

From: Roman Klochkov (kalimehtar at mail.ru)
Date: Sat May 24 05:47:34 EDT 2014

Thank you! That is what I wanted.

Sat, 24 May 2014 09:11:39 +0100 от Matthew Flatt <mflatt at cs.utah.edu>:
>At Sat, 24 May 2014 10:16:34 +0400, Roman Klochkov wrote:
>>  Is there a way to make C++ way inheritance: if superclass has the method, then 
>> override, else create new?
>> 
>> I see in manual, that public requires " method must not be present already in 
>> the superclass" and override requires "definition already present in the 
>> superclass".
>> 
>> Is it possible to not restrict the superclass?
>
>There's nothing built in (at the same level as `public` and `override`)
>to do that.
>
>You could use `method-in-interface?` to check whether a superclass has
>a method already and add the method if not:
>
> (define (fixup-for-m super%)
>   (if (method-in-interface? 'm (class->interface super%))
>       super%
>       (class super%
>         (super-new)
>         (define/public (m . args) (void)))))
>
> (class (fixup-for-m super%)
>   ....
>   (define/override (m ....) ....)
>   ....)
>


-- 
Roman Klochkov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140524/6c9fd9a0/attachment.html>

Posted on the users mailing list.