NIL

Singleton element of the domain DOM_NIL

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

NIL

Description

NIL is a keyword of the MuPAD® language which represents the singleton element of the domain DOM_NIL.

The kernel domain DOM_NIL has only one singleton element. NIL is a keyword of the MuPAD language which represents this element. NIL is not changed by evaluation, see DOM_NIL.

Most often, NIL is used to represent a "missing" or "void" operand in a data structure. The "void object" returned by null is not suitable for this, because it is removed from most containers (like lists, sets or expressions) during evaluation.

When a new array from the kernel domain DOM_ARRAY is created, its elements are initialized with the value NIL. The function op returns NIL for un-initialized array elements. Note, however, that an indexed access of an un-initialized array element returns the indexed expression instead of NIL.

Local variables of procedures defined by proc are initialized with NIL. Nevertheless, a warning is printed if one accesses a local variable without explicitly initializing its value.

In former versions of MuPAD, NIL was used to delete values of identifiers or entries of tables, by assigning NIL to the identifier or entry. This is no longer supported. One must use delete to delete values. NIL now is a valid value of an identifier and a valid entry of a table.

Examples

Example 1

Unlike the "void object" returned by null, NIL is not removed from lists and sets:

[1, NIL, 2, NIL], [1, null(), 2, null()], 
{1, NIL, 2, NIL}, {1, null(), 2, null()}

Example 2

NIL is used to represent "missing" entries of procedures. For example, the simplest procedure imaginable has the following operands:

op(proc() begin end)

The first NIL, for example, represents the empty argument list, the second the void list of local variables and the third the void set of procedure options.

Example 3

Array elements are initialized with NIL if not defined otherwise. Note, however, that the indexed access for such elements yields the indexed expression:

A := array(1..2): A[1], op(A,1)

delete A:

Example 4

Local variables in procedures are implicitly initialized with NIL. Still, a warning is printed if one uses the variable without explicitly initializing it:

p := proc() local l; begin print(l) end:  p():
Warning: Uninitialized variable 'l' is used.
  Evaluating: p

delete p:

Example 5

NIL may be assigned to an identifier or indexed identifier like any other value. Such an assignment no longer deletes the value of the identifier:

a := NIL:  b[1] := NIL:  a, b[1]

delete a, b:

See Also

MuPAD Functions

Was this topic helpful?