Question: conflict between with() and uses

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

Please Wait...