[self-interest] Re: The problem of dynamic inheritance

Jecel Assumpcao Jr jecel at merlintec.com
Thu Jan 15 01:28:30 UTC 2004


On Wednesday 14 January 2004 21:26, cyberbaixing wrote:
> Dear Jecel,
>
> Thank you for your receipt.
> May I understand the whole procedure in this way?
>
> The object a is a parent of c. When I send a message f to object c,
> after implements the 'c' printLine, due to the resend.f message,
> Lookup will look at its parent to run f. Since a has a method f, f is
> implemented. Furthermore, a also defines "change to a new parent
> named b" in method f. Because object c right has a slot b, so a's
> definition can work on c, finally c changes its parent to b and
> implement resend.f again.

That is correct.

> I add a new object d which is almost same as b in the original
> program, and I set d as the parent of a. I want to test whether I can
> get 'b' when I send a f.
> a _Define: (|
>         p*<-d.
>         f = ('a' printLine. p:b. f).
>
> |)
>
> b _Define: (|
>         f = ( 'b' printLine ).
>
> |)
>
> c _Define: (|
>         p1*<- a.
>         b =b.
>         f = ('c' printLine. resend.f).
>
> |)
>
> d _Define: (|
>         f = ('d' printLine. ).
>
> |)
>
> The output of a f has no change.
> But when I send a message: c f, I get infinite output of a and c
> like: ...
> a
> c
> a
> c
> ...
> till the stack overflows :P. I don't understand why object c falls
> into the endless output if I only add a parent to object a?

You didn't only add a parent to object a. You also renamed the parent in 
object c from 'p' to 'p1'. So the in code in method a>>f the 'p:' is no 
longer found in c (as before) but in a. Since c hasn't been changed 
(its parent is still a) sending 'f' to it will give you the result as 
before. You get infinite recursion, as I explained in a previous email. 

> I go on with adding a slot b =b. in object a. I still want to see
> whether I can see the output of 'b' by sending message "a f". The
> object a changes to this form:
> a _Define: (|
>         p*<-d.
>         b =b.
>         f = ('a' printLine. p:b. f).
>
> |)
>
> Too bad, the result of a f. also changes to endless output of a!
> ...
> a
> a
> a
> a
> ... till the stack overflows. Would you please tell me why?

The a>>f method is calling itself. In the version of your code that 
worked, the c>>f method was calling a different code with "resend.f". 
If you change the "f" to "resend.f" above it will work, but then your a 
object will be exactly the same as your original c object so it would 
be very strange if it didn't work.

-- Jecel



More information about the Self-interest mailing list