nm

11353 Reputation

20 Badges

13 years, 13 days

MaplePrimes Activity


These are replies submitted by nm

 

try to include all the code.

@Carl Love 

I am sorry, but when I tested it, it is not working when the return value is used inside another proc

boo:=proc()
 return 'NULL';
end proc;

foo:=proc()
  local a;
  a:=boo();
  if evalb(a=NULL) then
     print("a is null");
  else
     print("a is not null");
  fi;
end proc;

foo()

        "a is not null"

it should print "a is null"

it only works if the check is done at global level:

a:=boo();

if evalb(a=NULL) then
     print("a is null");
  else
     print("a is not null");
fi:

   "a is null"

 

So I am afraid this solution would not work for me as it stands, as I am going to use this deep inside module's proc. I do not know why it works only on global level. I think this is related to automatic evaluation at gloal level vs. inside a proc. I got bitten by this before.

I found if I add an eval, then it works:

boo:=proc()
 return 'NULL';
end proc;

foo:=proc()
  local a;
  a:=boo();
  if evalb(eval(a)=NULL) then
     print("a is NULL");
  else
     print("a is not NULL");
  fi;
end proc;


foo()

And now it prints correctly

        "a is NULL"

 

Or simply  

        if eval(a)=NULL then

will work also. But eval is needed since inside proc.  This is same problem I had in

https://www.mapleprimes.com/questions/230151-How-To-Distinguish-Between-Unevaluated

Where eval was needed when inside a proc() vs. on global level.  Maple has some strange evaluation rules.

 

@acer 

thanks. But repeated calls keep increasing the counter used. For example

This seems to be undocuments function? I saw reference to it at 

https://www.math.ubc.ca/~israel/advisor/advisor6/h1r1.htm

Is there a way to "reset" this counter so it does not keep increasing for each call? I have loop of 1,000's of ode's, so it will look bad after a while if this counter keeps increasing.

I can reset it back at end of the proc for example, so next call it starts again at zero. Then this might work.

 

@rlopez 

Yes, you are correct. That is what I meant to say, but was lazy and did not write it as precise as you said it.

@Carl Love 

The code that set currentdir() and libname was inside an exported proc, just like I showed in the example skelton I posted.

To verify, I just added these 2 lines back, build the mla and I get the error again. Removed these 2 lines, the error went away. These are lines

local main_dir:="C:/tmp/current_version/";          

currentdir(main_dir):   
:-libname := main_dir, :-libname;

These are the first thing I was doing in the exported proc.

All what I know, If I remove these, it works OK. If I can make a small example that shows this error will post it.

@Carl Love 

thanks for the additional info. If I get some free time, will try to make minimal example. 

@acer 

This was meant as skelton to show the problem cause. ofcourse there is a end module there. 

The code is over 10,000 lines long, and to make a MWE that will reproduce the problem might take me long time. I just showed what was the cause and to say it is resolved once I removed the re-setting of libname inside.

It is not critical for me to know the real cause, as I will not do this resetting of libname and setting currentdir() again inside the module. I will do this only from outside from now on.

It seems related to duplicate entries on the libname  that confused Maple. 

If I get some free time, I will try to reproduce this using small example.

 

@Joe Riel 

Thanks. I do create mla new each time, but you made me check few things.

I found the cause and fixed it.

I still do not know why. But this is what happens (I am still new at all of this mla stuff).

This is what I was doing. I create MLA file from the .mpl files just fine. set up libname to point to current folder where I have all the mla and all my .mpl files.

open worksheet, then do 

currentdir("C:/tmp/current_version/");
libname := currentdir(), libname;
dsolver_test:-test(); #this is a function inside dsolver_test which is inside the mla file

All OK so far. Except for that proc foo error which is local to dsolver_test moduie.

It turned out that in my dsolver_test.mpl file itself, in the test proc, I was doing this

dsolver_test := module()
option package;
....
export test:=proc()
local main_dir := "C:/tmp/current_version";
...

   #these two lines were the cause
   currentdir(main_dir):   
   :-libname := main_dir, :-libname;

      .....
     foo() #foo is just another local proc in this module
     .....
end proc;

local foo:=proc()
   ....
end proc;

end module;

 

It seems harmless. right? I was worried the currentdir might not be set by the caller. So I had it hardcoded again inside the module and was resetting libname again to make sure.

This was like this for 2 month now, never caused a problem except this last time for some reason.

The fix was remove the above code from inside the module. i..e removed these lines

  currentdir(main_dir):
   :-libname := main_dir, :-libname;

And made sure the worksheet which calls the module set up the currentdir and sets up libname before, which it was doing any way.

Now when I created mla again, and called it, the error went away.

I know it is not good idea to have currentdir and libname being set inside the .mpl file which goes into the mla, but this is just development code and had it there, before few days ago when I moved everything to use .mla.

Issue resolved, even though I am not sure why this caused the problem, but now I am ok. I will not set libname again from inside package, but only do it from outside.

Thanks for all the suggestions.

@Joe Riel 

Yes, I thought that at first, but I put the mla files in same folder where my code is, and no other place, then set up libname.

I also now used 

LibraryTools:-FindLibrary('dsolver_test')

And it printed the correct folder and path. No problems.

I can reproduce this problem all the time. It is only when it tries to call that specific proc() that it fails. I have no idea why it works with straight .mpl files and not when they are inside .mla.

I will try to debug this more today.

I really think something went wrong with the symbol table in the mla. it thinks the proc name is a symbol and not a procedure.

 

 

thanks for both answer. Both useful.

 

@Joe Riel 

So on Linux, Maple do not keep the mla file being used open? Does your makefile also delete the .mla file each time before making new one?

I thought keeping the .mla file open was on control of Maple and not the windows OS itself.

What prevents Maple from reading the mla file first time, and then closing it after the code is in memory? Or may be Maple keeps it open for some other reason.

@Carl Love 

yes, thanks. restart from all worksheets that use the mla is all what is needed.

But this is still annoying. As I could have 3-4 worksheets open at same time, all have used the .mla. So now I have to go find each worksheet, and click restart inside it, so I can update the mla.

It is easier just to close Maple and restart it, and then do the update. Not a big deal, just a little annoying that mla file is locked open when a process uses it. I thought Maple reads the code to memory and closes the mla file.

 

@Carl Love 

I know I can do that. But there must be some search path that Maple uses to locate .mla files. And that is what that webpage was saying. But since those environments variables are fake, I do not know what search path Maple uses.

I could use kernelopts(':-homedir')  for $HOME replacement for now.

But there should be some official search path that Maple searches to find .mla files other than libname. At least that what that page seems to say. May be I misunderstood that web page.

 

@Joe Riel 

I was trying to find out where to put my personal .mla file so Maple can automatically find it, without having to explicitly update libname each time. And that is what that web page says. 

If I do kernelopts('toolboxdir');  it returns [""]

 

 

@janhardo 

"y = g(y')   ( p = dy/dx)  is this still a d'Alembert ( Maple say yes ..no quadrature) "

restart;
ode:=y(x)=g(diff(y(x),x));
DEtools:-odeadvisor(ode)

 

"For x= 1 you get  y = 1. f(p)+g(p)  d'Alembert"

restart;
ode:=y(x)=f(diff(y(x),x))+g(diff(y(x),x));
DEtools:-odeadvisor(ode)

 

restart;
ode:=y(x)=x*f(diff(y(x),x))+g(diff(y(x),x));
DEtools:-odeadvisor(ode)

First 52 53 54 55 56 57 58 Last Page 54 of 91