## `Pref::typeCheck` -- type checking of formal parameters

#### Introduction

`Pref::typeCheck` determines the kind of type checking of procedure parameters.

#### Call(s)

`Pref::typeCheck(value)`
`Pref::typeCheck( <NIL>)`

#### Parameters

`value` | - | one of `Always`, `Interactive`, `None`, or `NIL`

#### Returns

the last defined value

#### Related Functions

`args`, `DOM_PROC`, `domtype`, `hastype`, `proc`, `testargs`, `testtype`, `Type`, `type`

#### Details

- The definition of a MuPAD procedure can be contain formal parameters. A type can be determined to every formal parameter with a new syntax. If the type checking will be enabled, the types of given parameters of such a procedure will be checked and results an error if it fails.
- As types MuPAD standard types and objects of the domain `Type` can be used. With `Type`, user defined types can be easily added to the system to extend the type checking mechanism.
- The arguments of `Pref::typeCheck` can be:
  `None`
    no parameter will be checked
  `Interactive`
    only when calculate interactively the formal parameters will be checked (default)
  `Always`
    the formal parameters will always be checked
- The default value `Interactive` means: When the user is calling a procedure `f`, their parameters will be checked, but all procedures, that will be called by the user called procedure `f`, performs no type checking.
- A call of `Pref::typeCheck` without arguments returns the current value. The argument `NIL` resets the default value, which is `Interactive`.

#### Example 1

The parameters of the procedure `f` must be an identifier followed by an integer:

    >> f:= proc(a : DOM_IDENT, b : DOM_INT)
           begin
             evalassign(a, b)
           end_proc:
       f(a, 2)

                                         2

Now `a` has the value `2`, but an identifier is expected:

    >> f(a, a + 2)

          Error: Wrong type of 2. argument (type 'DOM_INT' expected,
                 got argument 'a + 2');
          during evaluation of 'f'

#### Background

- The new 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)`. That means: `a` must be of the type `DOM_IDENT` and `b` must be of the type `Type::Integer`.
- The objects of `Type` covers generally more objects as the MuPAD kernel types.

#### Changes

- new function

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000