Maple 2021 Questions and Posts

These are Posts and Questions associated with the product, Maple 2021

I have plain text file generated, where each line has mixed numbers and strings. Some of the strings are latex. So they have "\" in them. The data is rectangle. same number of fields on each line, separated by commas.  I use CSV format to read the data to Maple.

I simply want to read this file using Import , which reads it into a matrix (using CSV format), and export it back right away using either ExportMatrix or Export and end up with the same exact file.

But Maple always adds extra "\" each time I export the matrix back to the file. So if I have initially "\sin x" in the file, after reading/writing the file 5 times without touching the data inside Maple, I end up with something like "\\\\\\\\\\\sin x" in the file at the end.

I could ofcourse not use ExportMatrix nor Export and write the data back to the file manually using fprintf using correct format for each field. But it is easier if I can get ExportMatrix to work since there are many fields some are integers, some are real and some are strings.

Here is a simple MWE which shows the problem. Originally I have this file on disk. Called test.txt and has 2 lines in it

1,"\sin x"
2,"this is second line"

Now after doing the following

data:=Import("test.txt",format="CSV",output=Matrix):  
ExportMatrix("test.txt",data,target=csv);

The file on disk now becomes

1,"\\sin x"
2,"this is second line"

And repeating the above one more time, the file becomes

1,"\\\\sin x"
2,"this is second line"

This ofcourse breaks all the latex strings in there.

Is there a way to prevent Maple from doing this? I looked at all the options in help, but do not see on so far.  I also tried Export but that did not work at all. So I'd like to see if ExportMatrix can do it, without adding an extra "\", otherwise, will have to use fprintf directly to export the data back to file.

edit

fyi, I ended up using fprintf to write the data back to disk. May be if there is a solution using ExportMatrix, will change back. This is what I ended up doing

File before

1,"\sin x"
2,"this is second line"

Now run this code

data:=Import("test.txt",format="CSV",output=Matrix):  
file_id := fopen("test.txt",WRITE):
nRows:=LinearAlgebra:-RowDimension(data);
for n to nRows do
    if n<nRows then
       fprintf(file_id,"%d,\"%s\"\n",data[n,1],data[n,2]);
    else
       fprintf(file_id,"%d,\"%s\"",data[n,1],data[n,2]);
    fi;
od;
fclose(file_id);

File after

1,"\sin x"
2,"this is second line"

Now the file is exactly the same as before reading it.

My actual data is more than the above two fields, but that makes the format string longer, that is all.

 

We have just released an update to Maple, Maple 2021.1.

Maple 2021.1 includes improvements to plotting, export to PDF and LaTeX, the user interface, the mathematics engine, and more. We strongly recommend that all Maple 2021 users install these updates.

This update is available through Tools>Check for Updates in Maple, and is also available from our website on the Maple 2021.1 download page, where you can also find more details.

In particular, please note that this update includes fixes to the sometimes missing plotting toolbar, the misplaced plot annotations on export, and a workbook saving problem, all reported on MaplePrimes.

Thanks for the feedback!

 

timelimit() has improved in Maple 2021, and I thought it works now for everything. 

https://www.mapleprimes.com/maplesoftblog/213986-Introducing-Maple-Learn-officially#comment204444

But unfortunately,, it still hangs on some dsolves when I was testing something. Here is an example

restart;
ode:=(y(x)^4-a^2*x^2)*diff(y(x),x)^2+2*a^2*x*y(x)*diff(y(x),x)+y(x)^2*(y(x)^2-a^2)=0;
timelimit(60,dsolve(ode,y(x)))

The above has one minute timeout. But its been running for 20 minutes now. Here is another example that hangs

restart;
ode:=(diff(y(x),x) = (-y(x)^2+4*a*x)^3/(-y(x)^2+4*a*x-1)/y(x));
timelimit(60,dsolve(ode,y(x)))

I have found many more dsolve examples that hang with timelimit. Will update later. May be they will help find the cause.

Hopefully this timelimit issue will be fixed in some future release.  hangs in Maple commands even when using timelimit makes it very hard to run long scripts that run over many problems, since do not know when/where it will hang and have to restart and clean things manually each time.

Window 10. Maple 2021

Update March 15,2022

Here is another example of timelimit taking so much longer than asking for, it is pretty much useless.

I will use this question to collect such examples in one place. Here I asked for one minute (60 seconds, CPU time) timeout. Maple actually timedout after using 1381 CPU seconds which is 23 times as much as requested.

restart;

ode:=x^2*(x^2+1)*diff(y(x),x$2)+7*x*exp(x)*diff(y(x),x)+9*(1+tan(x))*y(x)=0;
current_time:=time();
try
   timelimit(60,dsolve(ode))
catch:
   print("Good. Timelimit worked");
end try;
time_used := time()-current_time;

x^2*(x^2+1)*(diff(diff(y(x), x), x))+7*x*exp(x)*(diff(y(x), x))+9*(1+tan(x))*y(x) = 0

7292.312

"Good. Timelimit worked"

1381.078

1381/60.

23.01666667

 


 

Download timelimit_example_march_15_2022.mw

Help says

The timelimit function evaluates the expression x, but gives up if the evaluation takes longer than the number of seconds specified by t.
Note: In some cases, the execution may not abort at exactly the time limit imposed, but will abort as soon as it can do so safely.  This can happen when execution is in critical sections of certain built-in routines.

For me, the above makes no sense at all. What does "as soon as it can do safely"? I am not running the code to control an airplane flight full of people here. This is some code running on my PC at home to do some calculation. It can abort right away. It will not hurt me physically or hurt my PC to do so. 

So what does "do so safely" actually mean? Safety of what exactly?

Compare the above example to Mathematica where it times out at almost exactly to the requested timeout. Here I ask for 3 seconds timeout

I am not asking for exact timeout. But asking for 1 minute timeout and getting 8 minutes is not good at all.

1.5 minutes is OK. even 2 minutes is OK. 

I have more examples to add. But will do that later.

Update

Quick try with Maple 2022 shows timelimit has much improved. Here are 3 examples from above. First one asks for 60 seconds limit, it finishes in 288 seconds.   Second one asks for 60 seconds, it finishes in 96 seconds. Third one asks for 60 seconds and finishes in 73 second.

This is much much better than in Maple 2021. Thanks for the Maple engineers who improved this.

interface(version)

`Standard Worksheet Interface, Maple 2022.0, Windows 10, March 8 2022 Build ID 1599809`

restart;

ode:=x^2*(x^2+1)*diff(y(x),x$2)+7*x*exp(x)*diff(y(x),x)+9*(1+tan(x))*y(x)=0;
current_time:=time();
try
   timelimit(60,dsolve(ode))
catch:
   print("Good. Timelimit worked");
end try;
time_used := time()-current_time;

x^2*(x^2+1)*(diff(diff(y(x), x), x))+7*x*exp(x)*(diff(y(x), x))+9*(1+tan(x))*y(x) = 0

430.171

"Good. Timelimit worked"

288.766

ode:=(y(x)^4-a^2*x^2)*diff(y(x),x)^2+2*a^2*x*y(x)*diff(y(x),x)+y(x)^2*(y(x)^2-a^2)=0;
current_time:=time();
try
   timelimit(60,dsolve(ode))
catch:
   print("Good. Timelimit worked");
end try;
time_used := time()-current_time;

(y(x)^4-a^2*x^2)*(diff(y(x), x))^2+2*a^2*x*y(x)*(diff(y(x), x))+y(x)^2*(y(x)^2-a^2) = 0

718.953

"Good. Timelimit worked"

96.875

ode:=(diff(y(x),x) = (-y(x)^2+4*a*x)^3/(-y(x)^2+4*a*x-1)/y(x));
current_time:=time():
try
   timelimit(60,dsolve(ode))
catch:
   print("Good. Timelimit worked");
end try;
time_used := time()-current_time;

diff(y(x), x) = (-y(x)^2+4*a*x)^3/((-y(x)^2+4*a*x-1)*y(x))

"Good. Timelimit worked"

73.203

 

Download better_time_limit_with_maple_2022.mw

I found a big problem.

When adding kernelopts('assertlevel'=2): which I like to have it on all the time to catch (actual) errors, but now Maple server hangs then crashes on what should be no issue at all. 

This happens when I am using an object, which is used at global type. Here is a MWE

restart;

interface(warnlevel=4);
kernelopts('assertlevel'=2);

local ode_type:=module()
    option object;
    export ode;
    local ModuleLoad::static:=()->
           TypeTools:-AddType(':-ode_type', ode_type);
    ModuleLoad()       
end module:

A:=module()
  export foo:=proc()
    C:-foo();
  end proc;

  local B:=module()
    export foo:=proc()
      local ODE::ode_type;
      return ODE;
    end proc;
  end module;

  local C:=module()
    export foo:=proc()
      local the_ode::ode_type;  #THIS CAUSES the hang
                                #using the_ode::':-ode_type'; makes no difference
      #DEBUG
      the_ode:=B:-foo();
    end proc;
  end module;
end module;

There is nothing wrong with the above code as far as I can see. But now A:-foo(); crashes the Maple server.

If I change the line local the_ode::ode_type; to local the_ode; i.e. remove the type on the local variable, it works.

So assert thinks the type being returned is not ode_type

It also works if I remove the assert and keep the type there. Like this

restart;

interface(warnlevel=4);

local ode_type:=module()
    option object;
    export ode; 
    local ModuleLoad::static:=()->
           TypeTools:-AddType(':-ode_type', ode_type);
    ModuleLoad()       
end module:

A:=module()
  export foo:=proc()
    C:-foo();
  end proc;

  local B:=module()
    export foo:=proc()
      local ODE::ode_type;
      return ODE;
    end proc;
  end module;

  local C:=module()
    export foo:=proc()
      local the_ode::ode_type;  #NOW IT WORKS
      the_ode:=B:-foo();
    end proc;
  end module;
end module;

In my actual code, when I remove the kernelopts('assertlevel'=2); I do get correct final output. So it is not like I am bypassing some wrong code or something. The code works as expected.

Now now I have two choices, either remove  kernelopts('assertlevel'=2); or remove the type from the defintion of the local variables, when the type of object defined as above.

edit

another version below. When I copied the code above from my .mpl files to the worksheet to make a MWE, there was a local next to the object module (because that is how it is in my main code), and I did not notice it at first.

When I removed it to make new MWE in the worksheet, an error still shows up. But now Maple server do not hang/crash but it still does not like the assignment being made. So here is another version

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):


ode_type:=module()  #note that local ode_type:=module()  crashes Maple.
    option object;
    export ode; #can be list      
    local ModuleLoad::static:=()->
           TypeTools:-AddType(':-ode_type', ode_type);
    ModuleLoad()       
end module:

A:=module()
  export foo:=proc()
    C:-foo();
  end proc;

  local B:=module()
    export foo:=proc()
      local ODE::ode_type;
      return ODE;
    end proc;
  end module;

  local C:=module()
    export foo:=proc()
      local the_ode::ode_type;
      #DEBUG();
      the_ode:=B:-foo();
    end proc;
  end module;
end module;

And now A:-foo(); do not crash the server, but still gives error

     Error, (in foo) assertion failed in assignment to the_ode, expected ode_type, got ODE

Why? since ODE is of type ode_type, and I am returning. Can one not return Object like this? 

Is there something I am doing wrong?

 

 

is it possible for a string such as "res:=boo()" to be evaluated after calling parse, and have res have the value that the function boo() returned?

Now, it does not work. I must do   res:=eval(parse("boo()")) , meaning the result of the call to boo() is outside the string.

Here is an example of what I mean

boo:=proc()
   return 99;
end proc;  

foo:=proc()
  local s,res,i;
  s:="res:=boo()";
  eval(parse(s)):
  print(res);
end proc;

foo();

The above does not work. It displays res but this works

boo:=proc()
   return 99;
end proc;  

foo:=proc()
  local s,res,i;
  s:="boo()";
  res:=eval(parse(s)):
  print(res);
end proc;

foo();

The above works, and prints 99.

The reason I am asking, is that I was thinking of storing in a data base the complete Maple command as string, along with the LHS of the call, and just load the string the evaluate it, and it will have res automatically set.

It is no problem if this can't work, I could always just eval the command itself, without the assignment being there. Just thought to ask if there is a way.

 

I have about 30 modules under one root common module.  The total code is about 25,000 lines.

Currently during development, when I change a line of code and want to run a test, I just do

interface(warnlevel=4);
kernelopts('assertlevel'=2):
read   "my_root_module.mpl";
#run some test 

From a worksheet. This works fine, but it is very slow. it takes now about 8-10 minutes to finish each time.

So each time I make small change to the source code, which all sit in separate .mpl plain text files, I have to wait and wait for the read to complete.

This is way too slow. 

The thing is, my my_root_module.mpl files includes child modules (using the $include directive), and each child module might also have $include to pull in its own child modules, if any. Each module is onbe separate .mpl file.

So at the end my_root_module.mpl will end up reading all the code, which is now about 25,000 lines over 30 or so modules. Here is an example of the layout I have

my_root_module.mpl
=======
export my_root_module:=module()
$include  "B.mpl"   
$include  "C.mpl"                            
$include  "D.mpl"   
   export foo:-proc()....     B:-foo().... end proc;
end module:

B.mpl
=======
local B:=module()
$include  "B1.mpl"   
$include  "B2.mpl"                            

   export foo:=proc()..... end proc;
end module:

C.mpl
=======
local C:=module()
$include  "C1.mpl"   

   export foo:=proc()..... end proc;
end module:

etc...

There must be faster way to do this. Having to wait about 10 minutes each time to test one small code change each time is not practical.

What do others do when they develope large code in Maple? Is this a typical time?

I do not want to break my main modules into separate name spaces again in order to  use separate mla for each module, so that my changes only affects one mla file.  This will speed things, as I would then only have to rebuild one small modules, the one I changed.

But I want to put all my modules under one common module, which acts just as a common name space, and have only one mla file.

Are there ways to speed  reading mpl file?

Edit

Thanks to all the answers. It turned out indeed to be the slow Maple GUI again. The option interface(prettyprint= 0) did not help in the worksheet to speed the GUI.

I wrote the commands to read the mpl file and build the mla in a file, and used the DOS command line, and turned off the warning messages using DOS option, and now it finished almost instantly.

"C:\Program Files\Maple 2021\bin.X86_64_WINDOWS\cmaple.exe" UPDATE_MLA.mpl 1> nul

    memory used=18.6MB, alloc=73.3MB, time=0.52

Notice, in the above 1>nul will not even display the warning messages on the terminal. 2>nul does not work, since these are not error messages. Here are the different redirection options from the net

 

But even without using this redirection, and keeping the messages scroll on the terminal, it was still very very fast from the command line

I complained about how slow the Maple Java GUI when it comes to scrolling and how it can can cause  slow down many times before, so will not complain again about. May be one day Maplesoft will fix this.

1) Without the aid of a graph, find the absolute maximum and minimum values of the function

f(x)=36x6 +2665x4 +240x−675+4534x2 −5836x3−516x5 over the interval [0,4]

2) Find points P and Q on the parabola y = 1 − x 2 so that the triangle ABC formed by the x-axis and the tangent lines at P and Q is an equilateral triangle.

I noticed PDEtools:-Solve hangs sometimes on some input where solve does not. When I change the solver for PDEtools:-Solve to use solve, it did not hang.

This means PDEtools:-Solve default solver is something else. I did not see what it is by looking at help.

Here is an example

restart;
eq:=[1/3*(-334*I*(-4807763*I+27000*I*2^(1/2)+60*(1746675+72116445*2^(1/2))^(1/2))^(1/3)-2*(-4807763*I+27000*I*2^(1/2)+60*(1746675+72116445*2^(1/2))^(1/2))^(2/3)+56978)/(-4807763*I+27000*I*2^(1/2)+60*(1746675+72116445*2^(1/2))^(1/2))^(1/3)*v[1]-20*I*2^(1/2)*v[2] = 0, (-18000*I*2^(1/2)+33400*I-40*(1746675+72116445*2^(1/2))^(1/2)-40*(-167*I*(1746675+72116445*2^(1/2))^(1/2)+75150*2^(1/2)+10*(-4807763*I+27000*I*2^(1/2)+60*(1746675+72116445*2^(1/2))^(1/2))^(2/3)+145445)/(-4807763*I+27000*I*2^(1/2)+60*(1746675+72116445*2^(1/2))^(1/2))^(1/3))/(167*I*(-4807763*I+27000*I*2^(1/2)+60*(1746675+72116445*2^(1/2))^(1/2))^(1/3)+(-4807763*I+27000*I*2^(1/2)+60*(1746675+72116445*2^(1/2))^(1/2))^(2/3)-28489)*v[2]-20*I*2^(1/2)*t = 0];

solve(eq,[v[1],v[2]]); #OK
PDEtools:-Solve(eq,[v[1],v[2]],solver=solve); #OK
PDEtools:-Solve(eq,[v[1],v[2]]); #hangs

 

Maple 2021

I am merging two separate modules  B,C to be child modules inside one main A module.

Now, I found the code breaks, because uses does not work any more.

Before merging, C module did uses B. But now this gives an error when both B,C sit inside one parent module.  An example make this easier to explain

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):

A:=module()

   export B:=module()
     export foo:=proc()
         print("In B:-foo()");
     end proc;
   end module;

   export C:=module()
      uses B; #this cases problem
      export boo:=proc()
           foo();
      end proc;
   end module;
end module;

Error, (in A:-C) no bindings were specified or implied

Changing uses B; to uses A:-B; does not help. I get error Error, (in A:-C) `A` does not evaluate to a module

I also tried uses :-A:-B; , now this does not give error, but it does not work. i.e. when doing  A:-C:-boo() Maple does not end up calling foo() inside module B as expected.

One way to avoid all this, is not to use uses B inside the module and do this instead

A:=module()

   export B:=module()
     export foo:=proc()
         print("In B:-foo()");
     end proc;
   end module;

   export C:=module()      
      export boo:=proc()
           B:-foo(); 
      end proc;
   end module;
end module;

But it means I have to now change lots of code inside the C module, and add an explicit B:- everywhere

This is how it was before the merging

B:=module()
   export foo:=proc()
       print("In B:-foo()");
   end proc;
end module;

C:=module()  
  uses B;    #no problem now
  export boo:=proc()
      foo();  #this now uses B:-foo() automatically due to uses.
  end proc;
end module;

The above works. Now I can do C:-boo() and it works as expected.

The question is: How to make it work after moving both C and B inside one parent module so I do not have to change lots of code? I tried many things, but can't get it to work.

Maple 2021 on windows 10

Edit

Thanks for the answers below. I think I have to change my code then either way to add a prefix to the call. I actually always use the long form of the call for everything as in module:-function() but for one function, which I use so much everywhere, using the fully qualified name would make things hard to read.  This function converts Maple expressions to Latex after some filtering. Here is an example

cat(",toX(y),"' = f_0(",toX(f),")",toX(y),"+f_1(",toX(x),")",toX(g),"^n \\tag{2}, etc.....")

Now the function toX comes from one module, the one I had uses for it. Now I have to change the above to becomes

",module_name:-toX(f),"' = f_0(",module_name:-toX(x),")",module_name:-toX(y),"+f_1(",module_name:-toX(x),")",module_name:-toX(g),"^n \\tag{2}

Since my strings are very long as it is, (program generates Latex on the fly as it runs), this will make them even longer and harder to read.

But I can change all this in the editor, using global search and replace.

I was just hoping I do not have to just because I moved the modules all into one main module. I still do not understand why Maple does not allow uses when moving the modules inside one bigger module, but I guess this is by design.

Hello

I have a couple of large lists that will be further processed.  One of the steps is to index a list using another list (a list of indices).  A short example will be something like

L:=[2,1,4,3,7,6,8,3,4,5];
ind:=[2,2,3,3,5,6,7,1,4,10];

The solution 

L1:=L[ind]:

does not seem to be a good choice since it takes longer than the following solution

 

L1:=Threads:-Map(w->L[w],ind):

 

Since I am not a Maple expert, it is very likely that is a faster solution.   

 

Many thanks

 

hey guys, I'm curious if there is any way to do a group assignment like the following

JointNum := 3;
                    
seq(alpha[i], i = 1 .. JointNum) := 0, 0, 0;

which should as result be the following assignment

alpha[1], alpha[2], alpha[3]:=0,0,0

which is a valid assignment standalone but not works in the sequence style form . how can I implement this type of assignment

Hi, when I tried the simple example of Java OpenMaple on Mac, I can compile the code but couldn't run it. It complained about not finding libjopenmaple.jnilib. I checked that library directory, there was /libjopenmaple.jnilib but not libmaplec.dylib. Any suggestions?

> java -Djava.library.path=/Library/Frameworks/Maple.framework/Versions/2021/bin.APPLE_UNIVERSAL_OSX -classpath "$MAPLE/java/externalcall.jar:$MAPLE/java/Maple.jar:." test

Error loading libraries: java.lang.UnsatisfiedLinkError: /Library/Frameworks/Maple.framework/Versions/2021/bin.APPLE_UNIVERSAL_OSX/libjopenmaple.jnilib: dlopen(/Library/Frameworks/Maple.framework/Versions/2021/bin.APPLE_UNIVERSAL_OSX/libjopenmaple.jnilib, 1): Library not loaded: @rpath/libmaplec.dylib
  Referenced from: /Library/Frameworks/Maple.framework/Versions/2021/bin.APPLE_UNIVERSAL_OSX/libjopenmaple.jnilib
  Reason: image not found
java.lang.UnsatisfiedLinkError: /Library/Frameworks/Maple.framework/Versions/2021/bin.APPLE_UNIVERSAL_OSX/libjopenmaple.jnilib: dlopen(/Library/Frameworks/Maple.framework/Versions/2021/bin.APPLE_UNIVERSAL_OSX/libjopenmaple.jnilib, 1): Library not loaded: @rpath/libmaplec.dylib
  Referenced from: /Library/Frameworks/Maple.framework/Versions/2021/bin.APPLE_UNIVERSAL_OSX/libjopenmaple.jnilib
  Reason: image not found
    at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
    at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:383)
    at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:227)
    at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:169)
    at java.base/jdk.internal.loader.NativeLibraries.findFromPaths(NativeLibraries.java:316)
    at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:282)
    at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2440)
    at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:809)
    at java.base/java.lang.System.loadLibrary(System.java:1893)
    at com.maplesoft.openmaple.Engine.<clinit>(Engine.java:23)
    at test.main(test.java:22)
Exception in thread "main" java.lang.UnsatisfiedLinkError: 'long com.maplesoft.openmaple.Engine.getKernel(java.lang.String[], com.maplesoft.openmaple.EngineCallBacks, java.lang.Object, java.lang.Object)'
    at com.maplesoft.openmaple.Engine.getKernel(Native Method)
    at com.maplesoft.openmaple.Engine.<init>(Engine.java:44)
    at test.main(test.java:22)

 

 

Dear Community,

I try to slove a simple 2nd order ODE describing a simple pulley. Unfortunately dsolve does not like what I'm trying to do, and I get en error message. My goal is to plot travel distance, velocity and acceleration (  h(t), dh(t)/dt, d2h(t)/dt2 ) of the lifted weight. Could you pls. have a look what I'm doing wrong?

Also is there a way to transform this worksheet to a MapleSim document somehow? Worksheet attached.

tx in advance,

best regards

Andras

SimplePulley.mw

 

Since I installed Maple 2021 I have noticed a problem with the left corner of the menu and toolbar.  See the screenshot attached. I don't know if this is a general problem in Win10 or is this a problem with my installation.

Edit

I found the problem. Let me rephrase it. I keep original question below. 

This causes an error

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):
A:=module()
   export module_A1;
   local person_type;

   module person_type()
       option object;
       export name::string; 
       export age::string; 
    end module;

   module_A1:=module()
        export boo;
        boo:=proc()
          local X::A:-person_type;  #THIS LINE CAUSES ERROR
          #local X::person_type;    #THIS LINE ALSO CAUSES ERROR
          #local X;                 #THIS WORKS. No error
          X:=Object(person_type);
          return X;
       end proc;
    end module:
end module:

A:-module_A1:-boo();
           Error, (in boo) module does not export `person_type`

If I change  local X::person_type;  to just local X;  then no error is generated:

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):

A:=module()
   export module_A1;
   local person_type;

   module person_type()
       option object;
       export name::string; 
       export age::string; 
    end module;

   module_A1:=module()
        export boo;
        boo:=proc()
          local X;  
          X:=Object(person_type);  #now this works
          return X;
       end proc;
    end module:

end module:

A:-module_A1:-boo();

              `Object<<person_type,1822742359104>>`

So the problem was in the variable declaration. Maple for some reason does not like   local X::A:-person_type;  and does not like local X::person_type; but things seem to work by just removing the ::type altogother. 

So this solves this problem for me for now, I can keep person module local, and still use it in other child modules. Even though I do not understand why Maple complains about it when I use ::

original question. Can be ignored now.

I have one main module, with 2 submodules (child modules) A1 and A2. The child modules are all exported so they can be called from outside the main module.

But I want to have one additional module X as object, to share among the child modules A1 and A2, but without having to also export module X.

But Maple wants me to also export module X in order to use it inside the child modules A1, and A2.

Is there a way to share X  among child modules, without exporting it? I only want X be visible to child modules (i.e. modules inside the main module)

The module X has option object and I want to use it as just a type basically (instead of using Record).

Here is an example

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):
A:=module()
   export module_A1,module_A2;
   local person_type;

   module person_type()
       option object;
       export name::string; 
       export age::string; 
    end module;

   module_A1:=module()
        export boo;
        boo:=proc()
          local X::A:-person_type;
          X:=Object(A:-person_type);
          return 1;
       end proc;
    end module:

   module_A2:=module()
        export boo;
        boo:=proc()
          local X::A:-person_type;
          X:=Object(A:-person_type);
          return 1;
       end proc;
    end module:

end module:

Now the call A:-module_A1:-boo(); fail with Error, (in boo) module does not export `person_type`

This can be fixed by changing local person_type;  to export person_type;  but this means person_type can now be seen from outside the main package.

In Ada, it is possible to have private data type shared among child packages. How to do the same in Maple?

 

 

First 33 34 35 36 37 38 39 Page 35 of 40