zenterix

405 Reputation

5 Badges

3 years, 127 days

MaplePrimes Activity


These are questions asked by zenterix

mpl files for sure are good for committing to a repository, especially if you are collaborating with someone in writing the code in those files. They can be opened in an editor and worked on just like in the normal course of working in other programming languages and collaborating.

Worksheets and Workbooks I would imagine are alright as well, right? In this case, they are meant to be opened in Maple of course, not in a code editor.

Now, what about mla files? I imagine that if someone obtained an .mla file I created (containing a package, say), and saved it in a path contained in their libname then they would have access to that package. Is this the standard way of sharing packages with others?

If I wrote a package and wanted to share it (via a Github repo, for instance, or simply by emailling) would it consist of a single .mla file?

I have a folder called Packages, and I added its path to libname. I have an .mla file in there that I have been experimenting with to learn about writing packages in Maple.

The workflow I have currently developed is as follows.

Imagine I am working on a library that does something specific. Just to give a simple example, let's say I want to write a package that has functions sum, add, multiply.

I create an mpl file and I edit it in VSCode which has a plugin with syntax highlighting. In this file I write my package, procedures, etc. At the end of the file I add a line that tells LibraryTools to save the package to an mla file that I am keeping in the same directory as the mpl file (for organizational purposes, not for any technicality).

So at this point both these files are in the Packages directory.

Now let's say I want to create another package for doing animations. I would do the same thing: an mpl file and an mla file.

At this point all four files are together in the Packages directory, because that is where Maple knows to search for mla files. 

However, this isn't very convenient if I want to use version control for each package individually.

To do this I would need to have the two files of each package in their own directory (like a subdirectory of Packages)

i can do this of course, by adding each of the two resulting directories (each with two files) to libname. 

But is it possible to tell Maple to simply search all subdirectories of the directory Packages?

In other words, in this workflow, must I update libname every time I make a new package (which consists of a directory, an mpl file, an mla file, and a git file)?

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.

Consider the sequence of numbers 1, 2, 3, 4, ...

Can we plot these points on the real line?

That is, just a line with dots on the numbers 1, 2, 3, 4, ...

It appears that using 2D math can generate hidden characters that make code not run. 

It seems like a lot of people think that using 1D math is a no-brainer, as if it had all the advantages and no disadvantages.

I am trying to write code for an object. I was using 2D math, because the automatic formatting of the code (italics, bold) makes it much easier to see and understand the code. Then again, I ran into an issue I face sometimes which is that code that looks absolutely perfect can't be parsed. 

I read that we can convert the code to 1D math and we will see hidden characters messing things up but that doesn't seem to be the case (or at least I can't seem to see the extra character). And in any case, it is just maddening and not a productive thing to have to do.

Is 1D math really the best user experience that is available? Is there really a tradeoff between legibility and useability in Maple 2022?

First 15 16 17 18 19 20 Page 17 of 20