Question: How to overload a method in module with option object?

Maple 2023.1 will not let me overload a method for an object when using _self.  Is there a way around this?

module person()
   option object;
   local the_name::string:="*",the_age;

   export set_info::static:= overload(
   [
      proc(_self,the_name::string,$) option overload;
          _self:-the_name:=the_name;
      end proc,

      proc(_self,the_name::string,the_age::integer, $) option overload;
          _self:-the_name:=the_name;
          _self:-the_age:=the_age;
      end proc
   ]);

   export get_name::static:=proc(_self,$)
      RETURN(_self:-the_name);
   end proc;
end module;

And now when I do 

o:=Object(person);
o:-set_info("me");
o:-set_info("me",20)

Error, (in person:-set_info) `me` does not evaluate to a module
Error, invalid input: no implementation of person:-set_info 
matches the arguments in call, 'person:-set_info("me",20)'

The problem goes away by removing `_self` as first argument in signature of the overloaded method. But then I will not be able to use _self any more inside the methods.

There is no problem overloading the method when using normal module, or one that does not use _self. For example this works

restart;

module person() 
   export set_info:= overload(
   [
      proc(the_name::string,$) option overload;
          print(the_name);
      end proc,

      proc(the_name::string,the_age::integer, $) option overload;
          print(the_name);
          print(the_age);
      end proc
   ]);
end module;

person:-set_info("me");
person:-set_info("me",20)

How to make the first example above work? I need to overload a method inside an module with option object that uses _self

update

I found a workaround. But it is not good, but for now. For the overloaded method, instead of using 
           o:-set_info("me");

This works instead

         set_info(o,"me");

So the following now works

o:=Object(person);

#o:-set_info("me");   #do not use with overloaded
#o:-set_info("me",20); #do not use with overloaded

set_info(o,"me");  #now works OK with no error
set_info(o,"me",20); #now works OK with no error

o:-get_name();  #OK since this method  is not overloaded
o:-get_age();  #OK since this method  is not overloaded

I do not understand why _self can't be used with overloaded methods and if this a bug or by design. 

Maple 2023.1 on windows 10

67588

interface(version);

`Standard Worksheet Interface, Maple 2023.1, Windows 10, July 7 2023 Build ID 1723669`

restart;

67588

module person()
   option object;
   local the_name::string:="*",the_age;

   export set_info::static:= overload(
   [
      proc(_self,the_name::string,$) option overload;
           #print("Inside first overloaded set_info");
          _self:-the_name:=the_name;
      end proc,

      proc(_self,the_name::string,the_age::integer, $) option overload;
          #print("Inside second overloaded set_info");
          _self:-the_name:=the_name;
          _self:-the_age:=the_age;
      end proc
   ]);

   export get_name::static:=proc(_self,$)
      RETURN(_self:-the_name);
   end proc;

   export get_age::static:=proc(_self,$)
      RETURN(_self:-the_age);
   end proc;
end module;

module person () local the_name::string, the_age; option object; end module

o:=Object(person);
#o:-set_info("me");
#o:-set_info("me",20);

set_info(o,"me"):
set_info(o,"me",20):

o:-get_name();
o:-get_age();

module person () local the_name::string, the_age; option object; end module

"me"

20

 

Download self_with_overloaded.mw

Please Wait...