[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: You just found a wand of polymorphism (+2, cursed)



Quoting Bertrand Petit:
> 	In an empty editor I insert a TEST-SNIP% object (derived from
> the STRING-SNIP% class) and just after it I insert a plain
> #\newline. When I get back the inserted snip (with find-snip), the
> returned object is no longer a TEST-SNIP% instance: evaluating
> « (is-a?  (find-snip 0 'after #f) test-snip%) » yields a #f. I
> expected here to have my snip back as it was inserted.

See the `split' method on snip%. The editor is adding the newline to
your snip, then immediately afterwards decides to split it. I expect
that you didn't override `split', so the resulting snips are insteances
of string-snip%.

> 	Also: how can I find the class of a given unknown object such
> as the one I got back from FIND-SNIP?

In general, getting a class from an object might expose a class that a
library intended to be private. So it isn't supported.

But you can always extract an interface from an object. Every class has
an associated interface (but objects can't be instantiated via the
interface, and a new class cannot be derived from it).

Matthew