with - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


with

interactive package management utilities

 

Calling Sequence

Parameters

Description

Objects supporting with

Examples

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.  In such cases, use the long form of command names, or use a use statement. See the Examples.

• 

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 } );

,1,2,1,2

(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.

with( combinat );

Chi,bell,binomial,cartprod,character,choose,composition,conjpart,decodepart,encodepart,eulerian1,eulerian2,fibonacci,firstcomb,firstpart,firstperm,graycode,inttovec,lastcomb,lastpart,lastperm,multinomial,nextcomb,nextpart,nextperm,numbcomb,numbcomp,numbpart,numbperm,partition,permute,powerset,prevcomb,prevpart,prevperm,randcomb,randpart,randperm,rankcomb,rankperm,setpartition,stirling1,stirling2,subsets,unrankcomb,unrankperm,vectoint

(2)

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

,a,b,a,b

(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 top-level 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 :-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 table-based package as an argument that redefines a top-level name results in the top-level definition being unavailable (until you issue a restart command or start a new session).

print( minimize );

procexprFP::algebraic,initial::listname=algebraic,location::truefalsefalse,minimum::algebraicNULL,scaled::truefalsefalse...end proc

(4)

with( simplex ):

print( minimize );

procobj...end proc

(5)

print( :-minimize );

procobj...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 once-per-session 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;

f,s

Error, invalid input: with expects its 1st argument, pname, to be of type {`module`, package}, but received s

  

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:

p();

Reverse1,2,3

(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. Instead, use the use statement in a procedure.

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

p();

3,2,1

(8)
  

Note: Neither the with command, nor the unwith command, has any effect on help system searches. 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.

"DataFrame" objects

"DataSeries" objects

 

 

Examples

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

restart

combinat:-powerset1,2

,1,2,1,2

(9)

withcombinat

Chi,bell,binomial,cartprod,character,choose,composition,conjpart,decodepart,encodepart,eulerian1,eulerian2,fibonacci,firstcomb,firstpart,firstperm,graycode,inttovec,lastcomb,lastpart,lastperm,multinomial,nextcomb,nextpart,nextperm,numbcomb,numbcomp,numbpart,numbperm,partition,permute,powerset,prevcomb,prevpart,prevperm,randcomb,randpart,randperm,rankcomb,rankperm,setpartition,stirling1,stirling2,subsets,unrankcomb,unrankperm,vectoint

(10)

powerseta,b

,a,b,a,b

(11)

printminimize

procexprFP::algebraic,initial::listname=algebraic,location::truefalsefalse,minimum::algebraicNULL,scaled::truefalsefalse...end proc

(12)

withsimplex:

printminimize

procobj...end proc

(13)

print:-minimize

procobj...end proc

(14)

The with command works only at the top level. The following results in an error.

mmoduleoptionpackage;_exportf,s;ft→sint/cost;smoduleoptionpackage;_exportg;gt→expt/2end moduleend module:

if1=1thenwithm;withsendif

f,s

Error, invalid input: with expects its 1st argument, pname, to be of type {`module`, package}, but received s

The with command does not work when called within a procedure.

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

p

Reverse1,2,3

(15)

Instead, use the use statement in a procedure.

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

p

3,2,1

(16)

See Also

colondash

libname

module

module/package

packages

ProgrammingGuide/WritingPackages

restart

unwith

use

UsingPackages

Warning Messages