[racket] Confused by augment and inner

From: Stephen De Gabrielle (stephen.degabrielle at acm.org)
Date: Mon Sep 24 03:44:18 EDT 2012

wow - i got that wrong.

check this example from the reference

http://docs.racket-lang.org/reference/createclass.html#(form._((lib._racket/private/class-internal..rkt)._augment))

#lang racket

(define buzzer%
  (class object%
    (super-new)
    (define/pubment (buzz)
      (displayln "bzzzt")
      (inner (void) buzz))))
(define loud-buzzer%
  (class buzzer%
    (super-new)
    (define (buzz)
      (displayln "BZZZZZZZZZT"))
    (augment buzz)))
(send (new buzzer%) buzz)
;bzzzt
(send (new loud-buzzer%) buzz)
;bzzzt
;BZZZZZZZZZT

s.

On Mon, Sep 24, 2012 at 8:15 AM, Stephen De Gabrielle <
stephen.degabrielle at acm.org> wrote:

> The way I read it was the new function gets called instead of inner;
>
> #lang racket
>
> (define a%
>   (class object%
>     (super-new)
>     (define/pubment (hello)
>       (printf "Hello ")
>       (inner 0)
>       (printf "!~n "))))
>
>
> (define b%
>   (class a%
>     (super-new)
>     (define/augment (hello greg)
>       ;Call super here?
>       (printf " ~a ~n" greg))))
>
> (send (new b%) hello "Bob")
> -> Hello Bob!
>
> Is this right?
>
> Cheers,
> Stephen
>
>
>
> On Monday, September 24, 2012, Gregory Woodhouse wrote:
>
>> I am trying to understand how augmentable methods (as described in
>> section 13.5 of The Guide) work.
>>
>> Between the extremes of allowing arbitrary overriding and disallowing
>> overriding entirely, the class system also supports Beta-style
>> augmentable methods [Goldberg04]. A method declared with pubment is like
>> public, but the method cannot be overridden in subclasses; it can be
>> augmented only. A pubment method must explicitly invoke an augmentation
>> (if any) using inner; a subclass augments the method using augment,
>> instead of override.
>>
>>
>> From this I conclude that if, for example, I have a class a% and a
>> subclass b% and I want to augment a method of a% in b% I need to call inner
>> in the definition of the method in a%, not b%. Something like this
>>
>> #lang racket
>>
>> (define a%
>>   (class object%
>>     (super-new)
>>     (define/pubment (hello)
>>       (printf "Hello~n")
>>       (inner 0))))
>>
>> (define b%
>>   (class a%
>>     (super-new)
>>     (define/augment (hello)
>>       ;Call super here?
>>       (printf ", world!~n"))))
>>
>>
>> but this gives me an error (not really a surprise). My assumption is that
>> super should be used in the subclass when overriding a method, but if a
>> method is to be augmented any potential code in an augmenting class should
>> be invoked from the superclass and super is not used in the subclass.
>> Obviously, I'm missing something.
>>
>
>
> --
>
> --
> Stephen De Gabrielle
> stephen.degabrielle at acm.org
> Telephone +44 (0)20 85670911
> Mobile        +44 (0)79 85189045
> http://www.degabrielle.name/stephen
> ----
> Professor: Oh God! I clicked without reading!
> Cubert: And I slightly modified something I own!
> Professor: We're monsters!
>
>


-- 

--
Stephen De Gabrielle
stephen.degabrielle at acm.org
Telephone +44 (0)20 85670911
Mobile        +44 (0)79 85189045
http://www.degabrielle.name/stephen
----
Professor: Oh God! I clicked without reading!
Cubert: And I slightly modified something I own!
Professor: We're monsters!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120924/04dcc44c/attachment.html>

Posted on the users mailing list.