Package Question

11 views
Skip to first unread message

Diane Maclagan

unread,
Nov 23, 2009, 1:00:13 PM11/23/09
to Macaulay2
Hi,

I'm trying to create a package that will depend on the
NormalToricVarieties package, which in turn depends on Polyhedra. My
code has "needsPackage "NormalToricVarieties" " in it, but if I do not
also include "needsPackage "Polyhedra"" then I get the error:

testPackage.m2:28:32:(1):[10]: error: expected left hand parameter to
be a function, type, or a hash table

on the line when I try to overload an operator that is contained in
the Polyhedra package. This goes away when I add the "needsPackage
"Polyhedra"" line Is this the way it's supposed to work? ie do we have
to separately include all packages that the main included package
includes?

Thanks,

Diane

ps here's a stripped down version of the package:

needsPackage "NormalToricVarieties"

newPackage(
"testPackage",
Version => "",
Date => "23 November 2009",
Authors => {{
Name => "Diane Maclagan",
Email => "D.MaclaganREPLACEwarwick.ac.uk",
HomePage => "http://www.warwick.ac.uk/staff/
D.Maclagan"}},
Headline => "Test",
DebuggingMode => false
)

export {
}


---------------------------------------------------------------------------
--
CODE
---------------------------------------------------------------------------

--needsPackage
"Polyhedra";
needsPackage "NormalToricVarieties";



cones (ZZ, NormalToricVariety) := List => (i,X) ->(
<<"This is a function"<<endl;
);

---------------------------------------------------------------------------
--
DOCUMENTATION
---------------------------------------------------------------------------
beginDocumentation()



---------------------------------------------------------------------------
--
TEST
---------------------------------------------------------------------------

TEST ///
1+1==2
///

end

Dan Grayson

unread,
Nov 24, 2009, 12:28:30 PM11/24/09
to Macaulay2
I assume you're getting NormalToricVarieties from here:

svn://macaulay2.math.uiuc.edu/Macaulay2/trunk/M2/Macaulay2/packages/development/aim2009

I see now that we don't have a good design for packages that want to
provide the symbols of other packages to the user. Thank you for
pointing that out, Diane, that is very helpful!

Here is the current design. The package NormalToricVarieties starts
out, as recommended, with the line

needsPackage "Polyhedra"

and "cones" is one of the functions defined in the Polyhedra package.
So, the first time NormalToricVarieties is loaded, the dictionary of
Polyhedra will be added to the list of dictionaries (dictionaryPath),
and the function "cones" will be visible. Now imagine we do

needsPackage "NormalToricVarieties"

twice. The second time the file is not loaded and the command at the
top is not run, so the functions defined in Polyhedra are not made
available; all that happens is that the dictionary of
NormalToricVarieties is added to the dictionary path. That's what's
plaguing you: the second time, it's happening inside your package, and
thus "cones" is not visible there.

So, for now, please load the dependent package explicitly. In the
near future I will fix it by adding an option to newPackage that
specifies a list of names of packages whose symbols should be made
available to the user who loads the package currently being defined.
I suppose those symbols should also be made available to the code
inside the current package. Packages whose symbols are needed only by
the code inside the current package, and not by the user, can continue
to be loaded with "needsPackage" inside the current package; but
perhaps now is a convenient time to add a further option to
"newPackage" that specifies a list of names of packages needed
internally. If so, we might have something like this:

newPackage( "Foo",
ExportedPackages => {"Bar","Gar"},
ImportedPackages => {"Far", "Par"}
)

(Would those be good names for the options?)

Diane Maclagan

unread,
Nov 24, 2009, 4:51:01 PM11/24/09
to Macaulay2
Thanks Dan.

Re: your last question, if "ExportedPackages" means ones that are
available to the user after loading my package, and "ImportedPackages"
means ones I'll need internally, then they look like good names to me.

Diane
Reply all
Reply to author
Forward
0 new messages