Question: use ... end use; outside module trouble

I am making changes in my code in order to make it work with Grid. This involves making many modules I had export on them as local.

I have lots of code of this form

use toX=A:-some_very_long_module_name:-toX in
local B := module() 
       export foo:=proc()
            toX(...);
       end proc;
end module;
end use;

This is done so I do not have to type A:-some_very_long_module_name:-toX() all the time as toX() is a very common call I make all over the place in many different modules.

This was working fine, except when I now changed some_very_long_module_name module to be local.

I really do not want to change all my code and change toX(...) to the explicit fully qualified name  some_very_long_module_name:-toX(....)

I could probably look into using alias instead, but I do not like aliases.

But before doing this, any one knows why this now makes Maple not happy? And if it possible to make use....end use while keep this long named module local?

Below is work sheet showing 4 examples. The first one is how I had things before, where the module was export.

The second and third examples showing the problems that show up when changing the module to local.

The last one showing it works if I remove use...end use and just type the full long name.

my goal is to keep this long named module local, but still use  use...end use. around other modules which needs to make calls to it. Just to safe typing, that is all. 

Any ideas to try are welcome. 

 

restart;

 

Original code work, but module has to be export

 

A := module()

  export main_entry:=proc()
     B:-foo();
  end proc;

  export some_very_long_name:= module() #NOTICE, export
        export toX:=proc(n::integer)::integer;
              n+1;
        end proc;
  end module;

  use toX=A:-some_very_long_name:-toX in  #works now
  local B:= module()
     export foo:=proc()
         toX(1);
     end proc;
  end module;
  end use;

end module;

_m1906974412096

A:-main_entry()

2

 

Example 1 where it now fails, since changed to local

 

A := module()

  export main_entry:=proc()
     B:-foo();
  end proc;

  local some_very_long_name:= module() #NOTICE, now local
        export toX:=proc(n::integer)::integer;
              n+1;
        end proc;
  end module;

  use toX=A:-some_very_long_name:-toX in
  local B:= module()
     export foo:=proc()
         toX(1);
     end proc;
  end module;
  end use;

end module;

_m1907025773216

A:-main_entry()

Error, (in foo) module does not export `some_very_long_name`

 

Example 2 remove A:- in the use call

 

A := module()

  export main_entry:=proc()
     B:-foo();
  end proc;

  local some_very_long_name:= module() #NOTICE, now local
        export toX:=proc(n::integer)::integer;
              n+1;
        end proc;
  end module;

  use toX= some_very_long_name:-toX in #notice, removed A:-
  local B:= module()
     export foo:=proc()
         toX(1);
     end proc;
  end module;
  end use;

end module;

Error, (in anonymous procedure created in anonymous module instantiated by anonymous module) nameless local variable in procedure

 

 

 

 

Example 3. One solution is to type the full name and remove use....end use; But I am trying to avoid this.

 

A := module()

  export main_entry:=proc()
     B:-foo();
  end proc;

  local some_very_long_name:= module() #NOTICE, now local
        export toX:=proc(n::integer)::integer;
              n+1;
        end proc;
  end module;
  
  local B:= module()
     export foo:=proc()
         some_very_long_name:-toX(1); #this works
     end proc;
  end module;


end module;

_m1907023851968

A:-main_entry()

2

 


 

Download trouble_with_use.mw

Please Wait...