[plt-scheme] override error
At Mon, 22 May 2006 09:49:28 -0400, David Richards wrote:
> "PLT MrED: Graphical Toolbox Manual" offers this code snippet:
>
> (define append-only-text%
> (class text%
> (inherit last-position)
> (override can-insert? can-delete?)
> (define (can-insert? s l) (= s (last-position)))
> (define (can-delete? s l) #f)
> (super-instantiate ())))
>
>
> ... which (in 301) produces this error message:
>
> class*: superclass method for override, overment, or rename-super is
> not overrideable: can-insert? for class: append-only-text%
The `can-insert' method can't be overridden, but it can be augmented:
(define append-only-text%
(class text%
(inherit last-position)
(augment can-insert? can-delete?)
(define (can-insert? s l) (and (= s (last-position))
(inner #t can-insert? s l)))
(define (can-delete? s l) #f)
(super-instantiate ())))
The different between "override" and "augment" is that the superclass
is in control of augments, whereas the subclass is in control for
overrides.
In this case, making `can-insert?' augmentable instead of overidable
means that a subclass can't forget to call `super' and allow insertions
when the superclass wouldn't have.
Meanwhile, the `inner' call above allows a subclass of
`append-only-text%' to further restrict inserts --- but not allow
inserts that `append-only-text%' would disallow.
Matthew