## `NIL` -- the singleton element of the domain `DOM_NIL`

#### Introduction

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

#### Call(s)

`NIL`

#### Related Functions

`delete`, `FAIL`, `null`

#### Details

- 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 arrays or 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 an array or table.

#### 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()}

                   [1, NIL, 2, NIL], [1, 2], {NIL, 1, 2}, {1, 2}

#### 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)

          NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL

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)

                                     A[1], NIL

    >> 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' used;
          during evaluation of 'p'

                                        NIL

    >> 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]

                                     NIL, NIL

    >> delete a, b:

#### Changes

- Assigning `NIL` to identifiers or entries of arrays or tables does no longer delete their values.

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