It seems that "instanceMethods", without a class_object argument, does not return all the class methods that are available to the receiving class object (whereas it returns correctly all the instance methods in the case of instances).

The following code will invoke the routine "testInstanceMethods" with the class object .String, and then once more with a string instance with the value "hello world" in this case.

The routine "testInstanceMethods" checks whether the argument is a class object and if so uses it as the starting class to send the instanceMethods message, and if not gets the class object of an instance of a class. If a class object, then also the instance methods of .Class get queried in addition as these methods will be available as instance methods to any class object.

Next the superclasses of that clz get queried and as a result a loop over the classes .String, .Object, and .Comparable will be executed to get first the instance methods for each class, which get counted and collected, followed by querying all instanceMethods without a class_object argument.

Here the respective code:

   call testInstanceMethods.string say "="~copies(79)
   say call testInstanceMethods"hello world"

   ::routine testInstanceMethods
      use arg obj
      bIsClassObject=obj~isA(.class)
      if bIsClassObjectthen clz=obj
                        else clz=obj~class

      say "instanceMethods of" pp(obj)":" superclasses=clz~superClasses-- get array of superclasses 
say "=============" say "superclasses:" ppDoOver(superclasses)~makeString(,', ')
      say "=============" say sum=0 arrMeths=.array~new
      classes2ask= .array~of(clz)~~appendAll(superclasses)
      if bIsClassObjectthen classes2ask~append(.class)-- we have also the 
methods of .class available -- do o over
   .array~of(clz)~~appendAll(superclasses) do oover classes2ask
         tmpObj=bIsClassObject~?(o,obj)
         
arrOMeths=ppDoOver(.array~new~appendall(tmpObj~instanceMethods(o)~allIndexes~sort))
         arrMeths~appendAll(arrOMeths)
         sum+=arrOMeths~items
         say "---> " pp(tmpObj)"~instanceMethods("pp(o)"), arrOMeths~items:" 
pp(arrOMeths~items)", methods:" if arrOMeths~items>0 then say " " arrOMeths~makeString(,', ')
         say end say say "arrMeths~items:" arrMeths~items"sum:" sum
      say "-"~copies(79)
      say tmpObj=bIsClassObject~?(clz,obj)
      say "allMeths, result of:" pp(tmpObj)"~instanceMethods:" 
allMeths=ppDoOver((bIsClassObject~?(o,obj))~instanceMethods~allIndexes~sort)
      say "allMeths~items:" allMeths~items
      say "===> allMeths:"allMeths~makeString(,', ')
      say "allMeths~items:" allMeths~items
      say

   ::routine pp
      return "["arg(1)"]" ::routine ppDoOver
      use arg o
      arrOut=.array~new
      do valover o
         arrOut~append(pp(val))
      end return arrOut

Running this program will yield the following output:

   instanceMethods of [The String class]:
   =============
   superclasses: [The Object class], [The Comparable class]
   =============

   --->  [The String class]~instanceMethods([The String class]), 
arrOMeths~items: [17], methods:
          [ALNUM], [ALPHA], [BLANK], [CNTRL], [CR], [DIGIT], [GRAPH], [LOWER], 
[NEW], [NL], [NULL], [PRINT], [PUNCT], [SPACE], [TAB], [UPPER], [XDIGIT]

   --->  [The Object class]~instanceMethods([The Object class]), 
arrOMeths~items: [33], methods:
          [], [ ], [<>], [=], [==], [><], [CLASS], [COPY], [DEFAULTNAME], 
[HASHCODE], [HASMETHOD], [IDENTITYHASH], [INIT], [INSTANCEMETHOD], [INSTANCEMETHODS], 
[ISA], [ISINSTANCEOF], [ISNIL], [NEW], [OBJECTNAME], [OBJECTNAME=], [REQUEST], [RUN], 
[SEND], [SENDWITH], [SETMETHOD], [START], [STARTWITH], [STRING], [UNSETMETHOD], [\=], 
[\==], [||]

   --->  [The Comparable class]~instanceMethods([The Comparable class]), 
arrOMeths~items: [0], methods:

   --->  [The Class class]~instanceMethods([The Class class]), arrOMeths~items: 
[34], methods:
          [<>], [=], [==], [><], [ACTIVATE], [ANNOTATION], [ANNOTATIONS], 
[BASECLASS], [COPY], [DEFAULTNAME], [DEFINE], [DEFINEMETHODS], [DELETE], [ENHANCED], 
[HASHCODE], [ID], [INHERIT], [ISABSTRACT], [ISMETACLASS], [ISSUBCLASSOF], [METACLASS], 
[METHOD], [METHODS], [MIXINCLASS], [NEW], [PACKAGE], [QUERYMIXINCLASS], [SUBCLASS], 
[SUBCLASSES], [SUPERCLASS], [SUPERCLASSES], [UNINHERIT], [\=], [\==]


   *arrMeths~items: **84**sum: 84*
   
-------------------------------------------------------------------------------

   allMeths, result of: [The String class]~instanceMethods:
   *allMeths~items: **66*
   ===> allMeths:[], [ ], [<>], [<>], [=], [=], [==], [==], [><], [><], 
[ACTIVATE], [ANNOTATION], [ANNOTATIONS], [BASECLASS], [CLASS], [COPY], [COPY], [DEFAULTNAME], 
[DEFAULTNAME], [DEFINE], [DEFINEMETHODS], [DELETE], [ENHANCED], [HASHCODE], [HASHCODE], [HASMETHOD], [ID], 
[IDENTITYHASH], [INHERIT], [INIT], [INSTANCEMETHOD], [INSTANCEMETHODS], [ISA], [ISABSTRACT], 
[ISINSTANCEOF], [ISMETACLASS], [ISNIL], [ISSUBCLASSOF], [METACLASS], [METHOD], [METHODS], [MIXINCLASS], 
[NEW], [OBJECTNAME], [OBJECTNAME=], [PACKAGE], [QUERYMIXINCLASS], [REQUEST], [RUN], [SEND], [SENDWITH], 
[SETMETHOD], [START], [STARTWITH], [STRING], [SUBCLASS], [SUBCLASSES], [SUPERCLASS], [SUPERCLASSES], 
[UNINHERIT], [UNSETMETHOD], [\=], [\=], [\==], [\==], [||]
   *allMeths~items: **66*

   
===============================================================================

   instanceMethods of [hello world]: ============= superclasses: [The Object 
class], [The
   Comparable class] ============= ---> [hello world]~instanceMethods([The 
String class]),
   arrOMeths~items: [117], methods: [], [ ], [%], [&], [&&], [*], [**], [+], [-], 
[/], [//], [<],
   [<<], [<<=], [<=], [<>], [=], [==], [>], [><], [>=], [>>], [>>=], [?], 
[ABBREV], [ABS],
   [APPEND], [B2X], [BITAND], [BITOR], [BITXOR], [C2D], [C2X], [CASELESSABBREV],
   [CASELESSCHANGESTR], [CASELESSCOMPARE], [CASELESSCOMPARETO], 
[CASELESSCONTAINS],
   [CASELESSCONTAINSWORD], [CASELESSCOUNTSTR], [CASELESSENDSWITH], 
[CASELESSEQUALS],
   [CASELESSLASTPOS], [CASELESSMATCH], [CASELESSMATCHCHAR], [CASELESSPOS], 
[CASELESSSTARTSWITH],
   [CASELESSWORDPOS], [CEILING], [CENTER], [CENTRE], [CHANGESTR], [COMPARE], 
[COMPARETO],
   [CONTAINS], [CONTAINSWORD], [COPIES], [COUNTSTR], [D2C], [D2X], [DATATYPE], 
[DECODEBASE64],
   [DELSTR], [DELWORD], [ENCODEBASE64], [ENDSWITH], [EQUALS], [FLOOR], 
[FORMAT], [INSERT],
   [LASTPOS], [LEFT], [LENGTH], [LOWER], [MAKEARRAY], [MAKESTRING], [MATCH], 
[MATCHCHAR], [MAX],
   [MIN], [MODULO], [OVERLAY], [POS], [REPLACEAT], [REVERSE], [RIGHT], [ROUND], 
[SIGN], [SPACE],
   [STARTSWITH], [STRIP], [SUBCHAR], [SUBSTR], [SUBWORD], [SUBWORDS], 
[TRANSLATE], [TRUNC],
   [UPPER], [VERIFY], [WORD], [WORDINDEX], [WORDLENGTH], [WORDPOS], [WORDS], 
[X2B], [X2C], [X2D],
   [[]], [\], [\<], [\<<], [\=], [\==], [\>], [\>>], [|], [||] ---> [hello
   world]~instanceMethods([The Object class]), arrOMeths~items: [32], methods: [], [ 
], [<>], [=],
   [==], [><], [CLASS], [COPY], [DEFAULTNAME], [HASHCODE], [HASMETHOD], 
[IDENTITYHASH], [INIT],
   [INSTANCEMETHOD], [INSTANCEMETHODS], [ISA], [ISINSTANCEOF], [ISNIL], 
[OBJECTNAME],
   [OBJECTNAME=], [REQUEST], [RUN], [SEND], [SENDWITH], [SETMETHOD], [START], 
[STARTWITH],
   [STRING], [UNSETMETHOD], [\=], [\==], [||] ---> [hello 
world]~instanceMethods([The Comparable
   class]), arrOMeths~items: [1], methods: [COMPARETO] arrMeths~items: 150 sum: 
150
   
------------------------------------------------------------------------------- 
allMeths, result
   of: [hello world]~instanceMethods: allMeths~items: 150 ===> allMeths:[], [], [ 
], [ ], [%], [&],
   [&&], [*], [**], [+], [-], [/], [//], [<], [<<], [<<=], [<=], [<>], [<>], 
[=], [=], [==], [==],
   [>], [><], [><], [>=], [>>], [>>=], [?], [ABBREV], [ABS], [APPEND], [B2X], 
[BITAND], [BITOR],
   [BITXOR], [C2D], [C2X], [CASELESSABBREV], [CASELESSCHANGESTR], 
[CASELESSCOMPARE],
   [CASELESSCOMPARETO], [CASELESSCONTAINS], [CASELESSCONTAINSWORD], 
[CASELESSCOUNTSTR],
   [CASELESSENDSWITH], [CASELESSEQUALS], [CASELESSLASTPOS], [CASELESSMATCH], 
[CASELESSMATCHCHAR],
   [CASELESSPOS], [CASELESSSTARTSWITH], [CASELESSWORDPOS], [CEILING], [CENTER], 
[CENTRE],
   [CHANGESTR], [CLASS], [COMPARE], [COMPARETO], [COMPARETO], [CONTAINS], 
[CONTAINSWORD], [COPIES],
   [COPY], [COUNTSTR], [D2C], [D2X], [DATATYPE], [DECODEBASE64], [DEFAULTNAME], 
[DELSTR],
   [DELWORD], [ENCODEBASE64], [ENDSWITH], [EQUALS], [FLOOR], [FORMAT], 
[HASHCODE], [HASMETHOD],
   [IDENTITYHASH], [INIT], [INSERT], [INSTANCEMETHOD], [INSTANCEMETHODS], 
[ISA], [ISINSTANCEOF],
   [ISNIL], [LASTPOS], [LEFT], [LENGTH], [LOWER], [MAKEARRAY], [MAKESTRING], 
[MATCH], [MATCHCHAR],
   [MAX], [MIN], [MODULO], [OBJECTNAME], [OBJECTNAME=], [OVERLAY], [POS], 
[REPLACEAT], [REQUEST],
   [REVERSE], [RIGHT], [ROUND], [RUN], [SEND], [SENDWITH], [SETMETHOD], [SIGN], 
[SPACE], [START],
   [STARTSWITH], [STARTWITH], [STRING], [STRIP], [SUBCHAR], [SUBSTR], 
[SUBWORD], [SUBWORDS],
   [TRANSLATE], [TRUNC], [UNSETMETHOD], [UPPER], [VERIFY], [WORD], [WORDINDEX], 
[WORDLENGTH],
   [WORDPOS], [WORDS], [X2B], [X2C], [X2D], [[]], [\], [\<], [\<<], [\=], [\=], 
[\==], [\==], [\>],
   [\>>], [|], [||], [||] allMeths~items: 150

It seems that the instanceMethods message sent a class object does not return all methods. E.g. the class methods of .String seem to be missing from ".String~instanceMethods" (also NEW gets returned only once, which caused yesterday's question).

Looking at the results of sending instanceMethods to a string instance, returns the expected methods (those defined in .String and those inherited from the superclasses .object and .comparable).

Is there an error if sending instanceMethods to class objects, or is there an error in assumptions and/or the test code?

---rony

_______________________________________________
Oorexx-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/oorexx-devel

Reply via email to