
Calling Sequence


with(package, f1, f2, ...)


Parameters


package



name of a Maple package

f1, ...



(optional) names of commands in package





Description


•

The with(package) calling sequence makes the short form names of the commands of a Maple package available at the interactive level.

•

The with(package, f1, ...) calling sequence makes the short form names of the specified commands, f1, ..., of a Maple package available at the interactive level.

•

The with command provides functionality analogous to the use statement, but operates at the interactive level and applies to all packages. (The use statement provides facilities for working with modules only, particularly for modules that are not packages.)

•

The with command is effective only at the top level, and intended primarily for interactive use. Because with operates by using lexical scoping, it does not work inside the bodies of procedures, module definitions, or within statements. See the Examples section.

•

Packages, and how to write them, are explained briefly in module,package, and in detail in the Maple Programming Guide. The with command may not be used to bind the exports of a module that is not a package. The with command will issue a warning if called with a module that is not a package as argument.

•

When with is called with the name of a package as its argument, it binds the names exported by the package to the global namespace. This makes the exported names available to the interactive user at the top level of the Maple interaction loop. For example, to access the procedure combinat:powerset, you must enter the long form of the command name.

>

combinat:powerset( { 1, 2 } );

$\left\{{\varnothing}{\,}\left\{{1}\right\}{\,}\left\{{2}\right\}{\,}\left\{{1}{\,}{2}\right\}\right\}$
 (1) 

However, after using the with(combinat) command, you can use the short form command name powerset directly, without specifying the package to which that routine belongs.


For more information on using the long form and short form of package commands, see UsingPackages.

$\left[{\mathrm{Chi}}{\,}{\mathrm{bell}}{\,}{\mathrm{binomial}}{\,}{\mathrm{cartprod}}{\,}{\mathrm{character}}{\,}{\mathrm{choose}}{\,}{\mathrm{composition}}{\,}{\mathrm{conjpart}}{\,}{\mathrm{decodepart}}{\,}{\mathrm{encodepart}}{\,}{\mathrm{eulerian1}}{\,}{\mathrm{eulerian2}}{\,}{\mathrm{fibonacci}}{\,}{\mathrm{firstcomb}}{\,}{\mathrm{firstpart}}{\,}{\mathrm{firstperm}}{\,}{\mathrm{graycode}}{\,}{\mathrm{inttovec}}{\,}{\mathrm{lastcomb}}{\,}{\mathrm{lastpart}}{\,}{\mathrm{lastperm}}{\,}{\mathrm{multinomial}}{\,}{\mathrm{nextcomb}}{\,}{\mathrm{nextpart}}{\,}{\mathrm{nextperm}}{\,}{\mathrm{numbcomb}}{\,}{\mathrm{numbcomp}}{\,}{\mathrm{numbpart}}{\,}{\mathrm{numbperm}}{\,}{\mathrm{partition}}{\,}{\mathrm{permute}}{\,}{\mathrm{powerset}}{\,}{\mathrm{prevcomb}}{\,}{\mathrm{prevpart}}{\,}{\mathrm{prevperm}}{\,}{\mathrm{randcomb}}{\,}{\mathrm{randpart}}{\,}{\mathrm{randperm}}{\,}{\mathrm{rankcomb}}{\,}{\mathrm{rankperm}}{\,}{\mathrm{setpartition}}{\,}{\mathrm{stirling1}}{\,}{\mathrm{stirling2}}{\,}{\mathrm{subsets}}{\,}{\mathrm{unrankcomb}}{\,}{\mathrm{unrankperm}}{\,}{\mathrm{vectoint}}\right]$
 (2) 
>

powerset( { 'a', 'b' } );

$\left\{{\varnothing}{\,}\left\{{a}\right\}{\,}\left\{{b}\right\}{\,}\left\{{a}{\,}{b}\right\}\right\}$
 (3) 
•

As illustrated in the previous example, a list of the package export names bound to the top level is returned by with.


Note: To see a list of the packages for which the exports are bound to the top level, use the packages command. The packages are listed in binding order, with the most recently bound package at the end of the list.

•

The unwith command undoes the effects of prior calls to with. That is, when called with the name of a package as argument, unwith unbinds the package exports in the global namespace, any previous bindings of those exported names are restored.

•

The restart command clears the Maple internal memory, which includes unloading all packages, so that Maple acts (almost) as if just started.

•

Some package export names are identical to toplevel names with a global meaning. In addition, two or more packages may export some of the same names. Provided that a package whose exports have been bound by using the with command is implemented as a module, global names are still fully accessible. To access the global name foo after having bound a package that exports the name foo, use the prefix form of the $:$ operator, as in $:\mathrm{foo}$ .


For example, the global name Chi refers to a procedure that computes the hyperbolic cosine integral. After issuing a call to with( combinat), in which the name Chi is exported by the combinat package, the name Chi now refers to a different procedure for computing characters of symmetric groups. Because the combinat package is implemented as a module, the original meaning of Chi is still available by using the syntax :Chi. (For more information on :, see colondash.) This is not the case for packages that are implemented as tables. A with call with a tablebased package as an argument that redefines a toplevel name results in the toplevel definition being unavailable (until you issue a restart command or start a new session).

${\mathbf{proc}}\left({\mathrm{exprFP}}{::}{\mathrm{algebraic}}{\,}\left\{{\mathrm{initial}}{::}\left({\mathrm{list}}{}\left({\mathrm{name}}{\=}{\mathrm{algebraic}}\right)\right){\u2254}\left[{}\right]{\,}{\mathrm{location}}{::}{\mathrm{truefalse}}{\u2254}{\mathrm{false}}{\,}{\mathrm{minimum}}{::}{\mathrm{algebraic}}{\u2254}{\mathrm{NULL}}{\,}{\mathrm{scaled}}{::}{\mathrm{truefalse}}{\u2254}{\mathrm{false}}\right\}\right)\phantom{\rule[0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[0.0ex]{0.5em}{0.0ex}}{\mathbf{end\; proc}}$
 (4) 
${\mathbf{proc}}\left({\mathrm{obj}}\right)\phantom{\rule[0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[0.0ex]{0.5em}{0.0ex}}{\mathbf{end\; proc}}$
 (5) 
${\mathbf{proc}}\left({\mathrm{obj}}\right)\phantom{\rule[0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[0.0ex]{0.5em}{0.0ex}}{\mathbf{end\; proc}}$
 (6) 
•

Prior to arranging for the names exported by a package to be available at the top level, with executes either or both of two procedures that have, for historical reasons, come to be known as the system level initialization and user level initialization routines for a package, provided that they exist. A system level initialization routine is any procedure that is assigned to the name P/init, where P is the name of the package. It is called with no arguments. The user level initialization routine is a package export called init. It is called (if it exists) with no arguments after first calling the system level initialization routine. The system level initialization procedure is not called if the name P/Initialized has the value true, and this name is assigned the value true once the routine has been successfully executed. This allows you to put any oncepersession setup that needs to be done in the system level initialization, and anything that must be run each time with is called on your package can be performed in the user level initialization.

•

Note that with is effective only at the top level. In particular, the following results in an error.

>

m := module()
export f, s;
option package;
f := t >sin(t)/cos(t);
s := module()
export g;
option package;
g := t > exp(t/2);
end module;
end module: # a trivial package

>

if 1 = 1 then
with( m ); # this is okay
with( s ); # this fails because s is bound to :s
end if;

$\left[{f}{\,}{s}\right]$
 

The names m and s are bound globally at the time the if statement is simplified. Thus, when the if statement executes, the occurrence of the name s in the second call to with refers to the global name :s, not the exported name s from m.

•

Similarly, with is not effective when called within a procedure.

>

p := proc()
with( ListTools );
Reverse( [ 1, 2, 3 ] )
end proc:

${\mathrm{Reverse}}{}\left(\left[{1}{\,}{2}{\,}{3}\right]\right)$
 (7) 

The name Reverse is bound, when the procedure is simplified, to the global name :Reverse. The call to with does not execute until the procedure is called, at which point, the occurrence of the name Reverse has already been bound, and the with call is (apparently) ineffective. See the use statement for similar functionality in programs.


Note: Neither the with command, nor the unwith command, has any effect on the help system. It is not necessary to bind a package using with before you can access the help for the package or its exports.



Objects supporting with


•

The following objects support the with command with a separate implementation. See the help pages linked below for more details.



Examples


The following examples are reproduced from the Description section of this help page for your convenience.
>

$\mathrm{combinat}:\mathrm{powerset}\left(\left\{1\,2\right\}\right)$

$\left\{{\varnothing}{\,}\left\{{1}\right\}{\,}\left\{{2}\right\}{\,}\left\{{1}{\,}{2}\right\}\right\}$
 (8) 
>

$\mathrm{with}\left(\mathrm{combinat}\right)$

$\left[{\mathrm{Chi}}{\,}{\mathrm{bell}}{\,}{\mathrm{binomial}}{\,}{\mathrm{cartprod}}{\,}{\mathrm{character}}{\,}{\mathrm{choose}}{\,}{\mathrm{composition}}{\,}{\mathrm{conjpart}}{\,}{\mathrm{decodepart}}{\,}{\mathrm{encodepart}}{\,}{\mathrm{eulerian1}}{\,}{\mathrm{eulerian2}}{\,}{\mathrm{fibonacci}}{\,}{\mathrm{firstcomb}}{\,}{\mathrm{firstpart}}{\,}{\mathrm{firstperm}}{\,}{\mathrm{graycode}}{\,}{\mathrm{inttovec}}{\,}{\mathrm{lastcomb}}{\,}{\mathrm{lastpart}}{\,}{\mathrm{lastperm}}{\,}{\mathrm{multinomial}}{\,}{\mathrm{nextcomb}}{\,}{\mathrm{nextpart}}{\,}{\mathrm{nextperm}}{\,}{\mathrm{numbcomb}}{\,}{\mathrm{numbcomp}}{\,}{\mathrm{numbpart}}{\,}{\mathrm{numbperm}}{\,}{\mathrm{partition}}{\,}{\mathrm{permute}}{\,}{\mathrm{powerset}}{\,}{\mathrm{prevcomb}}{\,}{\mathrm{prevpart}}{\,}{\mathrm{prevperm}}{\,}{\mathrm{randcomb}}{\,}{\mathrm{randpart}}{\,}{\mathrm{randperm}}{\,}{\mathrm{rankcomb}}{\,}{\mathrm{rankperm}}{\,}{\mathrm{setpartition}}{\,}{\mathrm{stirling1}}{\,}{\mathrm{stirling2}}{\,}{\mathrm{subsets}}{\,}{\mathrm{unrankcomb}}{\,}{\mathrm{unrankperm}}{\,}{\mathrm{vectoint}}\right]$
 (9) 
>

$\mathrm{powerset}\left(\left\{'a'\,'b'\right\}\right)$

$\left\{{\varnothing}{\,}\left\{{a}\right\}{\,}\left\{{b}\right\}{\,}\left\{{a}{\,}{b}\right\}\right\}$
 (10) 
>

$\mathrm{print}\left(\mathrm{minimize}\right)$

${\mathbf{proc}}\left({\mathrm{exprFP}}{::}{\mathrm{algebraic}}{\,}\left\{{\mathrm{initial}}{::}\left({\mathrm{list}}{}\left({\mathrm{name}}{\=}{\mathrm{algebraic}}\right)\right){\u2254}\left[{}\right]{\,}{\mathrm{location}}{::}{\mathrm{truefalse}}{\u2254}{\mathrm{false}}{\,}{\mathrm{minimum}}{::}{\mathrm{algebraic}}{\u2254}{\mathrm{NULL}}{\,}{\mathrm{scaled}}{::}{\mathrm{truefalse}}{\u2254}{\mathrm{false}}\right\}\right)\phantom{\rule[0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[0.0ex]{0.5em}{0.0ex}}{\mathbf{end\; proc}}$
 (11) 
>

$\mathrm{with}\left(\mathrm{simplex}\right)\:$

>

$\mathrm{print}\left(\mathrm{minimize}\right)$

${\mathbf{proc}}\left({\mathrm{obj}}\right)\phantom{\rule[0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[0.0ex]{0.5em}{0.0ex}}{\mathbf{end\; proc}}$
 (12) 
>

$\mathrm{print}\left(:\mathrm{minimize}\right)$

${\mathbf{proc}}\left({\mathrm{obj}}\right)\phantom{\rule[0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[0.0ex]{0.5em}{0.0ex}}{\mathbf{end\; proc}}$
 (13) 
The with command works only at the top level. The following results in an error.
>

$m\u2254\mathbf{module}\left(\right)\phantom{\rule[0.0ex]{0.5em}{0.0ex}}\mathbf{option}\phantom{\rule[0.0ex]{0.5em}{0.0ex}}\mathrm{package}\;\phantom{\rule[0.0ex]{0.5em}{0.0ex}}\mathrm{\_export}\left(f\,s\right)\;\phantom{\rule[0.0ex]{0.5em}{0.0ex}}f\u2254t\→\mathrm{sin}\left(t\right)\/\mathrm{cos}\left(t\right)\;\phantom{\rule[0.0ex]{0.5em}{0.0ex}}s\u2254\mathbf{module}\left(\right)\phantom{\rule[0.0ex]{0.5em}{0.0ex}}\mathbf{option}\phantom{\rule[0.0ex]{0.5em}{0.0ex}}\mathrm{package}\;\phantom{\rule[0.0ex]{0.5em}{0.0ex}}\mathrm{\_export}\left(g\right)\;\phantom{\rule[0.0ex]{0.5em}{0.0ex}}g\u2254t\→\mathrm{exp}\left(t\/2\right)\phantom{\rule[0.0ex]{0.5em}{0.0ex}}\mathbf{end\; module}\phantom{\rule[0.0ex]{0.5em}{0.0ex}}\mathbf{end\; module}\:$

>

$\mathbf{if}\phantom{\rule[0.0ex]{0.3em}{0.0ex}}1=1\phantom{\rule[0.0ex]{0.3em}{0.0ex}}\mathbf{then}\phantom{\rule[0.0ex]{0.0em}{0.0ex}}\phantom{\rule[0.0ex]{2.0em}{0.0ex}}\mathrm{with}\left(m\right);\phantom{\rule[0.0ex]{0.0em}{0.0ex}}\phantom{\rule[0.0ex]{2.0em}{0.0ex}}\mathrm{with}\left(s\right)\phantom{\rule[0.0ex]{0.0em}{0.0ex}}\mathbf{end}\phantom{\rule[0.0ex]{0.3em}{0.0ex}}\mathbf{if}$

$\left[{f}{\,}{s}\right]$
 
The with command does not work when called within a procedure.
>

p := proc()
with( ListTools );
Reverse( [ 1, 2, 3 ] )
end proc:

${\mathrm{Reverse}}{}\left(\left[{1}{\,}{2}{\,}{3}\right]\right)$
 (14) 


