Type checking of formal parameters
MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
Always | Interactive | None) Pref::typeCheck(NIL) Pref::typeCheck()
Pref::typeCheck determines the kind of type
checking of procedure parameters.
The definition of a MuPAD® procedure may contain formal parameters. There is a syntax to attach a type specification to these parameters. If and when type checking is enabled, the types of actual parameters are checked against the type specifications and an error is raised if a parameter does not meet the specification.
Type specifications are used as the second parameter of
testtype. The most important
ones are Domain Types and objects of the domain Type. With Type, user defined
types can be easily added to the system to extend the type checking
The arguments of
Pref::typeCheck can be:
No parameters are checked.
Parameters entered interactively are checked. This is the default.
All formal parameters are checked.
The default value
Interactive means: When
the user is calling a procedure
f, its parameters
will be checked, but none of the procedures called by the user called
f performs type checking.
A call of
Pref::typeCheck without arguments
returns the current value. The argument
the default value, which is
We define a procedure
f expecting an identifier
and an integer:
f:= proc(a : DOM_IDENT, b : DOM_INT) begin evalassign(a, b, 1) end_proc: f(a, 2)
a has the value
but an identifier is expected:
Error: Invalid object '2'. Type of argument number 1 must be 'DOM_IDENT'. Evaluating: f
Parameter types are checked for every call.
Parameter types are checked for interactive calls, not for “inner” calls during the computation.
No parameter type checks are performed by the MuPAD kernel.
Explicit checks inside procedures still use the usual
Previously defined value
The syntax to test parameters directly (without a test in the
procedure body) is the formal parameter followed by a colon and then
the type object:
proc(a : DOM_IDENT, b : Type::Integer).
a must be of the type
be of the type
Note that you cannot use automatic type checking for arguments that are used for overloading inside the procedure.
The objects of the Type library are usually more general than the MuPAD kernel types.