Macaulay2 / M2

The primary source code repository for Macaulay2, a system for computing in commutative algebra, algebraic geometry and related fields.
https://macaulay2.com
347 stars 231 forks source link

strange loadPackage behavior #1487

Closed DanGrayson closed 4 years ago

DanGrayson commented 4 years ago

It's odd that loadPackage agrees to reload a package if given the package object rather than the name:


i10 : notify=true

o10 = true

i11 : loadPackage ConwayPolynomials
--closing database /Users/dan/src/M2/M2.git/M2/BUILD/dan/builds.tmp/einsteinium-development/usr-dist/x86_64-Darwin-MacOS-10.14.6/lib/Macaulay2/ConwayPolynomials/cache/rawdocumentation-dcba-8.db
--opening database /Users/dan/src/M2/M2.git/M2/BUILD/dan/builds.tmp/einsteinium-development/usr-dist/x86_64-Darwin-MacOS-10.14.6/lib/Macaulay2/ConwayPolynomials/cache/rawdocumentation-dcba-8.db
--beginDocumentation: using documentation database, skipping the rest of ../../../src/M2/M2.git/M2/Macaulay2/packages/ConwayPolynomials.m2
--package "ConwayPolynomials" loaded
--loaded ../../../src/M2/M2.git/M2/Macaulay2/packages/ConwayPolynomials.m2

o11 = ConwayPolynomials

o11 : Package

i12 : loadPackage "ConwayPolynomials"
../../../src/M2/M2.git/M2/Macaulay2/packages/ConwayPolynomials.m2:2:1:(3):[7]: error: package ConwayPolynomials not reloaded; try Reload => true
../../../src/M2/M2.git/M2/Macaulay2/packages/ConwayPolynomials.m2:2:1:(3):[7]: --entering debugger (type help to see debugger commands)
../../../src/M2/M2.git/M2/Macaulay2/packages/ConwayPolynomials.m2:2:1-11:18: --source code:
newPackage(
        "ConwayPolynomials",
        Version => "1.0", 
        Date => "October 23, 2008",
        Authors => {
             {Name => "Daniel R. Grayson", Email => "dan@math.uiuc.edu"}
             },
        HomePage => "http://www.math.uiuc.edu/~dan/",
        Headline => "a database of Conway polynomials"
        )
mahrud commented 4 years ago

Why is it strange? ConwayPolynomials is one of the preloaded packages, so the package object is defined, and loadPackage automatically sets Reload => true if the input is a package object, which is rather handy.

This behavior is documented as well:

Reload => a Boolean value, default value null, whether to reload the package, if it has been loaded before. If the input was an already loaded Package, this is automatically set to true.

DanGrayson commented 4 years ago

Why is it strange? ConwayPolynomials is one of the preloaded packages, so the package object is defined, and loadPackage automatically sets Reload => true if the input is a package object, which is rather handy.

This behavior is documented as well:

Reload => a Boolean value, default value null, whether to reload the package, if it has been loaded before. If the input was an already loaded Package, this is automatically set to true.

On second thought, it might be okay, because the sort of bug that is prevented by having loadPackage refuse to reload a package unless it was clearly intentional is the following: the user puts code such as loadPackage "Foo" into a package. Typically Foo is not already loaded, which is why Foo has to be given as a string here. The feature under discussion doesn't affect that.