Stem assignment is documented in section 1.13.4 of the Reference. Rick
On Mon, Oct 14, 2024 at 1:11 PM Gilbert Barmwater <gi...@bellsouth.net> wrote: > Thanks Rick! I modified the program to add: > > gColl = .stemX~new > gColl[foo] = 'One' > gColl[bar] = 'Two' > say gColl~items 'items' > gColl~count -- says '2' ! > > Rather than assigning the instance of the subclass to a stem variable, it > assigns it to a "normal" variable. Then it uses the '[]=' method to add > the two item to the collection. Now both the say statement and the count > message produce the same (expected) result. > > I have checked both the Programming Guide and the Reference and did not > find this documented. If you know differently, please let me know. > Otherwise I will open a documentation "bug". > > Gil B. > On 10/14/2024 12:10 PM, Rick McGuire wrote: > > 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 > listOorexx-devel@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/oorexx-devel > > -- > 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