Create a new data type (domain)

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.


newDomain(k, T)
newDomain(k, t)


newDomain(k) creates a new domain with key k.

newDomain(k, T) creates a copy of the domain T with new key k.

newDomain(k, t) creates a new domain with key k and slots from the table t.

Data types in MuPAD® are called domains. newDomain is a low-level function for defining new data types. Cf. the corresponding entry in the Glossary for links to documentation about domains and more comfortable ways of defining new data types. The help page of DOM_DOMAIN contains a tutorial example for defining a new domain via newDomain.

Technically, a domain is something like a table. The entries of this table are called slots or methods. They serve for extending the functionality of standard MuPAD functions, such as the arithmetic operations + and *, the special mathematical functions exp and sin, or the symbolic manipulation functions simplify and normal, to objects of a domain in a modular, object-oriented way, without the need to modify the source code of the standard function. This is known as overloading.

The function slot and the equivalent operator :: serve for defining and accessing a specific slot of a domain. The function op returns all slots of a domain.

Each domain has a distinguished slot "key", which is its unique identification. There can be no two different domains with the same key. Typically, but not necessarily, the key is a string. However, the key serves mainly for internal and output purposes. Usually a domain is assigned to an identifier immediately after its creation, and you access the domain via this identifier.

If a domain with the given key already exists, newDomain(k) returns that domain; both other forms of calling newDomain yield an error.


Example 1

We create new domain with key "my-domain". This key is also used for output, but without quotes:

T := newDomain("my-domain")

You can create elements of this domain with the function new:

e := new(T, 42);

With the slot operator ::, you can define a new slot or access an existing one:


T::key, T::myslot

T::myslot := 42: op(T)


If a domain with key k already exists, then newDomain(k) does not create a new domain, but returns the existing domain instead:

T1 := newDomain("my-domain"):

Note that you cannot delete a domain; the command delete T only deletes the value of the identifier T, but does not destroy the domain with the key "my-domain":

delete T, T1:
T2 := newDomain("my-domain"):
delete T2:

Example 2

There cannot exist different domains with the same key at the same time. Defining a slot for a domain implicitly changes all identifiers that have this domain as their value:

T := newDomain("1st"): T1 := T:

T1::mySlot := 42:

To avoid this, you can create a copy of a domain. You must reserve a new, unused key for that copy:

T2 := newDomain("2nd", T):
T2::anotherSlot := infinity:

delete T, T1, T2:

Example 3

You can provide a domain with slots already when creating it:

T := newDomain("3rd",
  table("myslot" = 42, "anotherSlot" = infinity)):
T::myslot, T::anotherSlot

delete T:



An arbitrary object; typically a string


A domain


The slots of the domain: a table

Return Values

Object of type DOM_DOMAIN.

See Also

MuPAD Domains

MuPAD Functions