As I was trying things with Maple OOP, I noticed strange behavior which I do not understand. I'll explain the problem in words first then given an example.
I have Person class. Then made one instance of it. In this class, there is one method which is defined to take in an object of same type as the class itself.
I found when I pass the object itself to its own method, it gives an error that the method expects a second argument of type person which is missing. But it is not missing.
Then when creating a second object of same type, and passing the second object, it worked!
Why? Here is MWE. Attached worksheet. I would have expected same behavior in both cases. EIther both work, or both do not work. As as long as the object being passed is the correct type (person).
It seems in the first case, Maple noticed the object being passed to the method happened to be same object where this method is, and it did not pass it. Hence the missing second argument. Is this a documented behaviour somewhere? (I made sure to make all method static though, so same code is used by all instances of the class. This is strange error message).
Ok, I am all set. I found a good way to do this. i.e. pass the object to one of its method. One has to make a copy of the object first and pass the copy. Can't use the same object. This is how I do it now.
export ModuleCopy::static:= overload(
proc(_self,proto, $)option overload;
print("Enter 2 args constructor of person");
proc(_self,proto, name::string, $) option overload;
print("Enter 3 args constructor of person");
_self:-name := name;
export process::static:=proc(_self, the_input::person,$)
print("the_input:-name = ",the_input:-name);
#p:-process(p); #instead of this do the following
Which works and gives
"Enter 3 args constructor of person"
p := Object<<2370600065568>>
"Enter 2 args constructor of person"
o := Object<<2370600048288>>
"the_input:-name = ", "me"
So I am now able to pass the object (or rather copy of it) as explicit argument to other methods and other modules. I am not sure why it does not work when using the object itself and had to make a copy.