prog::check
-- Checking
MuPAD objectsprog::check
checks MuPAD objects and draws
attention to errors and possible problems in programming.
prog::check
is very helpful for finding errors in
user-defined domains and procedures.
prog::check(object <, infolevel <,
options>>)
object |
- | procedure, function environment or domain to check,
the identifier All , or a list of objects |
infolevel |
- | positive integer that determines the completeness of messages |
options |
- | set of options, a single option, or
All |
Global |
- | report unknown global identifiers |
Local |
- | report unused local variables |
Localf |
- | report unused local variables and unused formal parameters |
Assign |
- | report assignments to formal parameters of procedures |
Level |
- | report applications of level to local variables |
Domain |
- | report undefined entries of domains (uses the slot
"undefinedEntries" ) |
Environment |
- | report assignments to environment variables |
Protect |
- | report assignments to (global) protected identifiers |
Special |
- | report special statements |
Escape |
- | report possible pointers to procedure environments |
prog::check
returns the void object null()
. Output messages are printed on
the screen.
debug
, prog::init
, prog::isGlobal
, prog::trace
, prog::getname
prog::check(
object)
checks the
MuPAD object object
. object
may be a
procedure, a function environment, or a domain. One may also give a list of
such objects.All
is given as first parameter, all defined
procedures, function environments and domains are checked (see anames
).infolevel
determines the amount of information given
while checking. The following values are useful:
options
can be a set
containing one or more of the following options, a single option or
All
(see options).All
, all are checked. Without options, the
set {Domain, Global, Level, Local, Protect}
is used.The arguments of hold
expressions are not checked.
local
, but never used in
the procedure.level
to local variables is reported.
Starting with MuPAD 2.0, local variables are simply
replaced by their values on evaluation and calling level
on them does not have any effect.save
, to catch error
conditions).HISTORY
.prog::check
prints warnings about procedures which may
require the option escape
.The following function contains a number of mistakes, some of which were actually legal in previous versions of MuPAD.
Lines 1
and 2
contains
declarations of local variables. In line 4
an undeclared
(global) variable g
is used. Line 7
applies
level
to a local
variable (the call simply returns the value of X
in
MuPAD 2.0). Line 10
contains an assignment to
a formal parameter. This parameter will be overwritten and its old
value lost:
>> f:= proc(X, Y) // 1 Local local a, b; // 2 Local begin // 3 g:= proc(X) // 4 Global option hold; // 5 begin // 6 a:= level(X, 2); // 7 Level a:= a + X // 8 end_proc; // 9 Y:= g(Y); // 10 Assign, Global end_proc: prog::check(f, 3)
'level' applied to variables: {X} in [f, proc in 'f'] Global idents: {g} in [f] Unused local var's: {b} in [f] Warnings: 3 [f]
Only search for global variables, but give more messages:
>> prog::check(f, 5, Global)
checking f (DOM_PROC) Warning: Global variable 'g' in f [] Warning: Global variable 'g' in f [] Global idents: {g} in [f] Warnings: 1 [f]
Now check everything:
>> prog::check(f, 5, All)
checking f (DOM_PROC) Warning: Global variable 'g' in f [] Warning: critical usage of 'level' on local variable 'X' in proc in 'f' [f] 'level' applied to variables: {X} in [f, proc in 'f'] Procedure environment of [f] used by [f, proc in 'f'] Warning: assignment to FORMAL parameter 'Y' in f [] Warning: Global variable 'g' in f [] Global idents: {g} in [f] Unused local var's: {b} in [f] Unused formal par's: {X} in [f] Assignments to formal parameters: {Y} in [f] Warnings: 5 [f]
prog::check
includes the functionality of the obsolete
functions misc::checkLib
and
misc::checkFunction
.