## `table` -- create a table

#### Introduction

`table``()` creates a new empty table.

`table``(index1 = entry1, index2 = entry2...)` creates a new table with the given indices and entries.

#### Call(s)

`table()`
`table(index1 = entry1, index2 = entry2...)`

#### Parameters

`index1, index2...` | - | the indices: arbitrary MuPAD objects
`entry1, entry2...` | - | the corresponding entries: arbitrary MuPAD objects

#### Returns

an object of type `DOM_TABLE`.

#### Related Functions

`_assign`, `_index`, `array`, `assignElements`, `delete`, `DOM_ARRAY`, `DOM_LIST`, `DOM_TABLE`, `indexval`

#### Details

- In MuPAD, tables are the most flexible objects for storing data. In contrast to arrays or lists, arbitrary MuPAD objects can be used as indices. Indexed access to table entries is fast and nearly independent of the size of the table. Thus, tables are suitable containers for large data.
- For a table `T`, say, an indexed call `T[index]` returns the corresponding entry. If no such entry exists, the indexed expression `T[index]` is returned symbolically.
- An indexed assignment of the form `T[index] := entry` adds a new entry to an existing table `T` or overwrites an existing entry associated with the index.
- `table` is used for the explicit creation of a table. There also is the following mechanism for creating a table implicitly.

  If the value of an identifier `T`, say, is neither a table nor an array nor a list, then an indexed assignment `T[index] := entry` is equivalent to `T := table(index = entry)`. I.e., implicitly, a new table with one entry is created. Cf. example 2.

  If the value of `T` was either a table or an array or a list, then the indexed assignment only inserts a new entry without changing the type of `T` implicitly.

- Table entries can be deleted with the function `delete`. Cf. example 3.
- `table` is a function of the system kernel.

#### Example 1

The following call creates a table with two entries:

    >> T := table(a = 13, c = 42)

                                     table(
                                       c = 42,
                                       a = 13
                                     )

The data may be accessed via indexed calls. Note the symbolic result for the index `b` which does not have a corresponding entry in the table:

    >> T[a], T[b], T[c]

                                   13, T[b], 42

Entries of a table may be changed via indexed assignments:

    >> T[a] := T[a] + 10: T

                                     table(
                                       c = 42,
                                       a = 23
                                     )

Expression sequences may be used as indices or entries, respectively. Note, however, that they have to be enclosed in brackets when using them as input parameters for `table`:

    >> T := table((a, b) = "hello", a + b = (50, 70))

                                table(
                                  a + b = (50, 70),
                                  (a, b) = "hello"
                                )

    >> T[a + b]

                                      50, 70

Indexed access does not require additional brackets:

    >> T[a, b] := T[a, b]." world": T

                             table(
                               a + b = (50, 70),
                               (a, b) = "hello world"
                             )

    >> delete T:

#### Example 2

Below, a new table is created implicitly by an idexed assigment using an identifier `T` without a value:

    >> delete T: T[4] := 7: T

                                      table(
                                        4 = 7
                                      )

    >> delete T:

#### Example 3

Use `delete` to delete entries:

    >> T := table(a = 1, b = 2, (a, b) = (1, 2))

                                table(
                                  (a, b) = (1, 2),
                                  b = 2,
                                  a = 1
                                )

    >> delete T[b], T[a, b]: T

                                      table(
                                        a = 1
                                      )

    >> delete T:

#### Changes

- In previous versions, an assignment of the object `NIL` to a table entry deleted this entry. Now `NIL` is assigned to that entry. Use `delete` to delete entries.

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