Documentation Center

  • Trial Software
  • Product Updates

prog::check

Checking objects

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

prog::check(object, <infolevel>, options)

Description

The call 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.

If 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:

  • 1

    summarizing number of warnings per checked object, if at least one warning occurs (default)

  • 2

    as 1, but a short message is printed even if no warning was produced

  • 3

    summary of warnings per checked object

  • 5

    displays each checked object, followed by individual warnings, followed by a summary and the number of warnings, if any.

  • 10 15

    additional outputs (for debugging/information)

options can be any of the described options.

With option All, all are checked. Without options, the set {Domain, Global, Interface, Level, Local, Protect, Save} is used.

    Note:   The arguments of hold expressions are not checked.

Examples

Example 1

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)
Critical usage of 'level' on local variable ' [f]
Function 'level' applied to variables: {X} in [f, proc in 'f']
Global idents: {g} in [f]
Unused local variables: {b} in [f]
Warnings: 3 [f]

Only search for global variables, but give more messages:

prog::check(f, 5, Global)
Checking f (DOM_PROC)
  Global variable 'g' in [f]
  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)
  Global variable 'g' in [f]
  Critical usage of 'level' on local variable ' [f]
  Function 'level' applied to variables: {X} in [f, proc in 'f']
  Procedure environment of [f] used by [f, proc in 'f']
  Assignment to formal parameter 'Y' in [f].
  Global variable 'g' in [f]
  Global idents: {g} in [f]
  Unused local variables: {b} in [f]
  Unused formal parameters: {X} in [f]
  Assignments to formal parameters: {Y} in [f]
  Warnings: 8 [f]

Global variables declared with the option "save" are allowed:

f:= proc(X)                   //  1  Local
      save g;                 //  2  Save
    begin                     //  3
      g:= X
    end_proc:
prog::check(f, 2, Global, Save)
Warnings: 0 [f]

Parameters

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

All

Enables all known options

Global

Report unknown global identifiers

Local

Report unused local variables

These are variables that were declared by local, but never used in the procedure.

Localf

Report unused local variables and unused formal parameters

The same as Local, but the same check is additionally performed for formal parameters of a procedure. Those are the argument names as given in the definition of the procedure.

Assign

Report assignments to formal parameters of procedures

Because a formal parameter will be overwritten, those assignments could indicate a programming error (however, not imperative).

Level

The application of 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.

Domain

Report undefined entries of domains (uses the slot "undefinedEntries")

Interface

Information about undefined entries of a domain interface are printed, i.e., entries in the domain interface, that are not defined as entries of the domain.

Environment

Information about assignments to environment variables of MuPAD are printed. These assignments could change the global behavior of MuPAD if the change is not undone (preferably using save, to catch error conditions).

Protect

Information about assignments to protected variables of MuPAD are printed.

Save

A message about a global identifier is suppressed, when the checked object is a procedure and the identifier is saved with option "save".

Special

Information about some special cases are printed. Currently, the only implemented special case is assignments to HISTORY.

Escape

prog::check prints warnings about procedures which may require the option escape.

Return Values

prog::check returns the void object null(). Output messages are printed on the screen.

See Also

MuPAD Functions

Was this topic helpful?