Items tagged with unwith

Feed App Center

It would seem that if a package is loaded at the "top-level" via with() and the worksheet also has a procedure definition which contains a 'uses' statement for the same package (OK, admittedly a bit redundant), the commands from the relevant package actually "go missing".

See the output from test4() in the attached.

I can't believe that this is deliberate, because when trying to 'compartmentalise' code, then a 'uses' statement in a procedure seems like a good idea. To have this fail because the "top-level" worksheet contains a with() statement loading the same package seems perverse.

Please don't post workarounds - I already know several ways to do achieve it. I'm trying to find out if this behaviour is "deliberate" or a "bug". If the latter, it has been around for a long time because I have checked all the way back to Maple 18: every version exhibits the same behaviour

  restart:

  kernelopts(version);
  test1:= proc(M::Matrix)
               uses LinearAlgebra:
               return MatrixInverse(M):
          end proc:
  test2:= proc(M::Matrix)
               return LinearAlgebra:-MatrixInverse(M):
          end proc:
  with(LinearAlgebra):
  test3:= proc(M::Matrix)
               return MatrixInverse(M):
          end proc:
  test4:= proc(M::Matrix)
               uses LinearAlgebra:
               return MatrixInverse(M):
          end proc:
  test1( Matrix( [[1,2],[3,4]]));
  test2( Matrix( [[1,2],[3,4]]));
  test3( Matrix( [[1,2],[3,4]]));
  test4( Matrix( [[1,2],[3,4]]));

`Maple 2020.0, X86 64 WINDOWS, Mar 4 2020, Build ID 1455132`

 

Matrix(2, 2, {(1, 1) = -2, (1, 2) = 1, (2, 1) = 3/2, (2, 2) = -1/2})

 

Matrix(2, 2, {(1, 1) = -2, (1, 2) = 1, (2, 1) = 3/2, (2, 2) = -1/2})

 

Matrix(2, 2, {(1, 1) = -2, (1, 2) = 1, (2, 1) = 3/2, (2, 2) = -1/2})

 

MatrixInverse(Matrix(%id = 18446744074373391174))

(1)

 

Download usewith.mw

Hi everybody,

I have written a module (let's say MyModule) that  I use as a package in a worksheet (with(MyModule)).

At some point in my worksheet I call the procedure MyProc which is part of MyModule.
I find it not to work as expected. So I modify it within MyModule and generate again the archive which contains this module.

Because my worksheet does a lot of things before the call to MyProc, I would like to test quickly the above modifications.
The idea is to do :
unwith(MyModule):  # packages() no longer exhibits its name
with(MyModule);      # to load the corrected one

Unfortunately, contrary to what happens with a "native" package,  the command unwith(MyModule) is ineffective:

  • once done showstat(MyProc) still displays the content of the procedure, and running  the command MyProc(...) proves that it still "exists" in the worksheet
     
  • forcing a reload of MyModule ( with(MyModule) ) and acanning again MyProc ( showstat(MyProc) ) reveals the code MyProc had when MyModule has been loaded for the first time.

 

Is it possible to "free" a user package through the "unwith" command ?

Hope to read you soon, TIA


PS : to be clearer

A worksheet contains  the definition of N procedures, plus the one of MyModule, and ends with the commands to generate an archive file named MyModule.mla.
MyModule is defined that way

MyModule := module()
option package

export Proc1 := eval(:-Proc1),
           ......
           MyProc := eval(:-MyProc),
           ......
           ProcN := eval(:-ProcN):
end module
 

 

Page 1 of 1