Task

Demonstrate how to make the object respond (sensibly/usefully) to an invocation of a method on it that it does not support through its class definitions.

Note that this is not the same as just invoking a defined method whose name is given dynamically; the method named at the point of invocation must not be defined.

This task is intended only for object systems that use a dynamic dispatch mechanism without static checking.



Related task

   Send an unknown method call.


procedure DynMethod(obj,meth,arglist[])
   local m
 
   if not (type(obj) ? ( tab(find("__")), ="__state", pos(0))) then 
      runerr(205,obj)                       # invalid value - not an object
 
   if meth == ("initially"|"UndefinedMethod") then fail  # avoid protected 
 
   m := obj.__m                                          # get methods list
   if fieldnames(m) == meth then                         # method exists?
      return m[meth]!push(copy(arglist),obj)             # ... call it
   else 
      if fieldnames(m) == "UndefinedMethod" then         # handler exists?
         return obj.UndefinedMethod!arglist              # ... call it
      else runerr(207,obj)                  # error invalid method (i.e. field)
end