No subject

From: ()
Date: Fri Jul 13 09:02:16 EDT 2012

#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.

--Boundary_(ID_Rj2ON1qN9uHGHUIN7cdPMg)
Content-type: text/html; CHARSET=US-ASCII
Content-transfer-encoding: quoted-printable

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html =
charset=3Dus-ascii"></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">I am =
trying to understand how augmentable methods (as described in section =
13.5 of The Guide) work.<div><br></div><div><span style=3D"font-family: =
serif; text-align: left; background-color: rgb(255, 255, 255); ">Between =
the extremes of allowing arbitrary overriding and disallowing overriding =
entirely, the class system also supports Beta-style&nbsp;</span><span =
style=3D"font-family: serif; text-align: left; background-color: =
rgb(255, 255, 255); font-style: italic; ">augmentable</span><span =
style=3D"font-family: serif; text-align: left; background-color: =
rgb(255, 255, 255); ">&nbsp;methods [</span><a =
href=3D"file:///Applications/Racket%20v5.3/doc/guide/doc-bibliography.html=
#(cite._.Goldberg04)" pltdoc=3D"x" style=3D"font-family: serif; =
text-align: left; background-color: rgb(255, 255, 255); =
">Goldberg04</a><span style=3D"font-family: serif; text-align: left; =
background-color: rgb(255, 255, 255); ">]. A method declared =
with&nbsp;</span><span class=3D"RktSym" style=3D"font-family: monospace; =
color: rgb(38, 38, 128); text-align: left; background-color: rgb(255, =
255, 255); "><a =
href=3D"file:///Applications/Racket%20v5.3/doc/reference/createclass.html#=
(form._((lib._racket/private/class-internal..rkt)._pubment))" =
class=3D"RktStxLink" pltdoc=3D"x" style=3D"text-decoration: none; color: =
black; ">pubment</a></span><span style=3D"font-family: serif; =
text-align: left; background-color: rgb(255, 255, 255); ">&nbsp;is =
like&nbsp;</span><span class=3D"RktSym" style=3D"font-family: monospace; =
color: rgb(38, 38, 128); text-align: left; background-color: rgb(255, =
255, 255); "><a =
href=3D"file:///Applications/Racket%20v5.3/doc/reference/createclass.html#=
(form._((lib._racket/private/class-internal..rkt)._public))" =
class=3D"RktStxLink" pltdoc=3D"x" style=3D"text-decoration: none; color: =
black; ">public</a></span><span style=3D"font-family: serif; text-align: =
left; background-color: rgb(255, 255, 255); ">, but the method cannot be =
overridden in subclasses; it can be augmented only. A&nbsp;</span><span =
class=3D"RktSym" style=3D"font-family: monospace; color: rgb(38, 38, =
128); text-align: left; background-color: rgb(255, 255, 255); "><a =
href=3D"file:///Applications/Racket%20v5.3/doc/reference/createclass.html#=
(form._((lib._racket/private/class-internal..rkt)._pubment))" =
class=3D"RktStxLink" pltdoc=3D"x" style=3D"text-decoration: none; color: =
black; ">pubment</a></span><span style=3D"font-family: serif; =
text-align: left; background-color: rgb(255, 255, 255); ">&nbsp;method =
must explicitly invoke an augmentation (if any) using&nbsp;</span><span =
class=3D"RktSym" style=3D"font-family: monospace; color: rgb(38, 38, =
128); text-align: left; background-color: rgb(255, 255, 255); "><a =
href=3D"file:///Applications/Racket%20v5.3/doc/reference/createclass.html#=
(form._((lib._racket/private/class-internal..rkt)._inner))" =
class=3D"RktStxLink" pltdoc=3D"x" style=3D"text-decoration: none; color: =
black; ">inner</a></span><span style=3D"font-family: serif; text-align: =
left; background-color: rgb(255, 255, 255); ">; a subclass augments the =
method using&nbsp;</span><span class=3D"RktSym" style=3D"font-family: =
monospace; color: rgb(38, 38, 128); text-align: left; background-color: =
rgb(255, 255, 255); "><a =
href=3D"file:///Applications/Racket%20v5.3/doc/reference/createclass.html#=
(form._((lib._racket/private/class-internal..rkt)._augment))" =
class=3D"RktStxLink" pltdoc=3D"x" style=3D"text-decoration: none; color: =
black; ">augment</a></span><span style=3D"font-family: serif; =
text-align: left; background-color: rgb(255, 255, 255); ">, instead =
of&nbsp;</span><span class=3D"RktSym" style=3D"font-family: monospace; =
color: rgb(38, 38, 128); text-align: left; background-color: rgb(255, =
255, 255); "><a =
href=3D"file:///Applications/Racket%20v5.3/doc/reference/createclass.html#=
(form._((lib._racket/private/class-internal..rkt)._override))" =
class=3D"RktStxLink" pltdoc=3D"x" style=3D"text-decoration: none; color: =
black; ">override</a></span><span style=3D"font-family: serif; =
text-align: left; background-color: rgb(255, 255, 255); =
">.</span><br><div><br></div><div><br></div><div>=46rom 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</div></div><div><br></div><div><div>#lang =
racket</div><div><br></div><div>(define a%</div><div>&nbsp; (class =
object%</div><div>&nbsp; &nbsp; (super-new)</div><div>&nbsp; &nbsp; =
(define/pubment (hello)</div><div>&nbsp; &nbsp; &nbsp; (printf =
"Hello~n")</div><div>&nbsp; &nbsp; &nbsp; (inner =
0))))</div><div><br></div><div>(define b%</div><div>&nbsp; (class =
a%</div><div>&nbsp; &nbsp; (super-new)</div><div>&nbsp; &nbsp; =
(define/augment (hello)</div><div>&nbsp; &nbsp; &nbsp; ;Call super =
here?</div><div>&nbsp; &nbsp; &nbsp; (printf ", =
world!~n"))))</div></div><div><br></div><div><br></div><div>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.</div></body></html>=

--Boundary_(ID_Rj2ON1qN9uHGHUIN7cdPMg)--

Posted on the users mailing list.