The classic trap. Assignment if a stem to a stem variable only works if the
right hand side is exactly an instance of the .Stem class, not a subclass.
Your stem subclass got assigned as the default value of the stem variable,
not as the base stem object.

Rick

On Mon, Oct 14, 2024 at 12:06 PM Gilbert Barmwater <gi...@bellsouth.net>
wrote:

>   I need some help in understanding the behavior of the following code.
> It creates two subclasses, one of List and one of Stem, that inherit
> from a mixin class which adds a single method named Count.  I would
> expect that method  to behave the same for instances of either subclass
> but it does not.  Here is the code:
>
> -- test the added Count method
>
>      aColl = .listX~new
>      aColl~append('One')
>      aColl~append('Two')
>      say aColl~items 'items'
>      aColl~count     -- says '2'
>
>      sColl. = .stemX~new
>      sColl.foo = 'One'
>      sColl.bar = 'Two'
>      say sColl.~items 'items'
>      sColl.~count    -- says '0' !
>
> -- a class to add a Count method to another class
> ::class addCount mixinclass Object public
>
> ::method count
>      say self~items
>
> ::class listX subclass list inherit addCount
>
> ::class stemX subclass stem inherit addCount
>
> The output is:
>
> 2 items
> 2
> 2 items
> 0
>
> --
> Gil Barmwater
>
>
>
> _______________________________________________
> Oorexx-devel mailing list
> Oorexx-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/oorexx-devel
>
_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel

Reply via email to