[racket] inherit, inherit/super, and inherit/inner in class syntax

From: Eric Tanter (etanter at dcc.uchile.cl)
Date: Sat Jun 15 08:25:55 EDT 2013

inner is for Beta-style inheritance, which is the dual of the typical way to do inheritance. Instead of having overriding methods that take precedence and can use super to call the base method, the base method has precedence and can call subclass methods using inner.

The best is to look at this paper:
David Goldberg, Robert Bruce Findler, and Matthew Flatt, “Super and Inner—Together at Last!,” Object-Oriented Programming, Languages, Systems, and Applications, 2004.http://www.cs.utah.edu/plt/publications/oopsla04-gff.pdf

HTH,

-- Éric


On Jun 14, 2013, at 6:54 PM, Christopher <ultimatemacfanatic at gmail.com> wrote:

> Dr./Mr./Ms. Takikawa, thank you for advancing my understanding.
> 
> I would still like to understand what inherit/inner is and how it works.  Can anyone else fill me in on this point?
> 
> --Christopher
> 
> 
> On Jun 14, 2013, at 4:13 PM, Asumu Takikawa <asumu at ccs.neu.edu> wrote:
> 
>> On 2013-06-14 14:39:57 -0600, Christopher wrote:
>>> So I have been trying to learn the ins and outs of Racket's class
>>> system.  I've a little puzzled when it comes to the "inherit"-forms.
>>> I've poured over the Racket Reference and fiddled with some
>>> experimental classes, but I'm still not clear.
>>> 
>>> My questions specifically are, What is the difference between inherit
>>> and inherit/super, and how does inherit/inner work?
>> 
>> Here's an example that hopefully shows the difference:
>> 
>> #lang racket
>> 
>> (define point%
>>   (class object%
>>     (inspect #f) ; to make example object easier to understand
>>     (super-new)
>>     (init-field [x 0] [y 0])
>>     (define/public (move-x dx)
>>       (new this% [x (+ x dx)] [y y]))))
>> 
>> (define fast-point%
>>   (class point%
>>     (super-new)
>>     (inherit/super move-x)
>>     ;; or you can inherit
>>     ;(inherit move-x)
>>     (define/public (move-fast dx)
>>       ;; only with inherit/super or override
>>       (super move-x (* dx 10))
>>       ;; with inherit, inherit/super, or override
>>       ;(move-x (* dx 10))
>>       )))
>> 
>> (send (new fast-point% [x 0] [y 2]) move-fast 3)
>> 
>> Notice that with `inherit/super`, you can use `super` on the method name
>> that you inherit from the superclass. Normally, you can only call
>> `super` on a method name that you are overriding.
>> 
>> On the other hand, with either `inherit` or `inherit/super`, you can
>> call the superclass method by just using the name.
>> 
>> I have never found the need to use `inherit/super` or `inherit/inner` in
>> my programs though. I always use `inherit`.
>> 
>> (If you wanted to know the rationale of why `inherit/super` exists, I'm
>> not sure. The commit log says it was added to replace `rename-super`
>> eventually)
>> 
>> Cheers,
>> Asumu
> 
> 
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users
> 



Posted on the users mailing list.