Question: how to have submodule in separate file?

my main module is getting big. I want to break it to main module, and submodule. But now everything is in the same .mpl file. I'd like to put the sub module in seperate mpl file. I do not know the syntax to do this and how to do it. I looked at the programming guide chapter 8.

Currently in main_module.mpl, lets say I have this

main_module:=module()
 option package;
 local C; 
 local sub_module;
 export main_entry;

 C:=99; #see if this can be "seen" from child module

 sub_module:= module()
    export main_entry;
    main_entry :=proc()
     print("In main_module:-sub_module:-main_entry(), C=",C):
    end proc;
  end module;
 
 main_entry :=proc()
   print("in main_module:-main_entry()"):
   sub_module:-main_entry();
 end proc;
end module;

Now main_module:-main_entry(); gives

                 "in main_module:-main_entry()"
       "In main_module:-sub_module:-main_entry(), C=", 99


I'd like to move the code of the submodule to another .mpl file. So I end up with two files, like this

# main_module.mpl
main_module:=module()
 option package;
 local C; 
 local sub_module;
 export main_entry;

 C:=99; #see if this can be "seen" from child module

 main_entry :=proc()
   print("in main_module:-main_entry()"):
   sub_module:-main_entry();
 end proc;
end module;

And

#sub_module.mpl
sub_module:= module()
    export main_entry;
    main_entry :=proc()
     print("In main_module:-sub_module:-main_entry(), C=",C):
    end proc;
 end module;

But when I do this, I can't call main_module:-main_entry(); since it gives error

Error, (in main_entry) `sub_module` does not evaluate to a module
I do not want to make sub_module a separate package. I want it to remain a sub module for the main module, so it can only be seen by the main module and no one else.

So logically sub_module is a child of main_module, but physically I want to put them in separate files to make it easier to modify.

I use plain text files for everything and use Maple to load the packages and test.

How does one go about doing this? How would this be done for the above example?

 

I tried $include "sub_module.mpl"; but it gives error.

main_module:=module()
 option package;
 local C; 
 local sub_module;
 export main_entry;

 C:=99; #see if this can be "seen" from child module
	
 $include "sub_module.mpl";

 main_entry :=proc()
   print("in main_module:-main_entry()"):
   sub_module:-main_entry();
 end proc;
end module;

Where the file "sub_module.mpl" contains the code for the submodule I want to insert at that location. When I read "main_module.mpl" Maple gives error

read "main_module.mpl";

Error, on line 10, syntax error, unexpected string:
 $include "sub_module.mpl";

This is too advanced for me. I am still learning module and package use in Maple.

thanks

Please Wait...