Question: After creating a package, how do we save changes to the package code? Ie, if we want to add stuff to the package, how do we update it?

Note: It seems in the course of writing this question I found the answer, but I am still interested in any tips on the best workflow to update a library. Here is the original post (annotated ex post in bold):

I have successully created my own package in Maple. I basically used LibraryTools:-Create to create an .mla file and then I used LibraryTools:-Save, passing in the name of my package and the path to the .mla file. I did this in a worksheet.

I can import it with the command with(MyPackage).

I'd like to add code to the package.

I have a package defined in as

module MyPackage()
  option package;
  export MyModule;

  module MyModule()
    (...)
  end;
 end;

I would like to add a procedure to be exported inside the package.

I tried to add the procedure, save the file, and then use LibraryTools:-Save again, but the error I get is 

Error (in MyPackage) attempting to assign to 'MyPackage' which is protected. Try declaring local 'MyPackage'; see ?protect for details.

I tried to unprotect the name 'MyPackage' but this gives another error

Error, on line %1, unexpected end of input. Error while reading '%1' (this turned out to be a missing semicolon on the Save command, which was the last command in the mpl file. The error messags are quite unhelpful)

Note: As I mentioned before, I did the initial saving of the package from a worksheet (the package code was in a code editing region in the worksheet). In the current attempt to add the new procedure, I copied the code to an .mpl file so I could edit it in a code editor (VSCode). At the end of this file I added the commands to LibraryTools:-Save the package again to the same .mla file as before.

My attempt to unprotect the name "MyPackage" involved simply adding unprotect('MyPackage') as the first line in this .mpl file.

I then used the command read to execute the mpl file from within a worksheet.

What am I doing wrong, and what is the recommended workflow to be able to work on a package?

If I try to update a simple variable in the .mla file it seems to work.

EDIT: The problem seems to be the use of the named module initially, ie module MyPackage().

If I try the whole process again (write a simple package and save it to the mla file) but this time I use the syntax

MyTestPackage = module()

then I can update it no problem (at least for a simple package that I just wrote; for the actual package with my real code I still get even though Maple is able to read the mpl file without a problem, apparently there is still some issue while trying to save. 

Error, on line %1, unexpected end of input. Error while reading '%1'   (turns out it was the missing semicolon)

In summary: don't used named module syntax.

Please Wait...