Create a new data type (domain)
This functionality does not run in MATLAB.
newDomain(k) 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.
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.
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); domtype(e)
With the slot operator ::, you can define a new slot or access an existing one:
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"): op(T1)
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"): op(T2); delete T2:
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: op(T); op(T1);
T1::mySlot := 42: op(T); op(T1);
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: op(T); op(T2);
delete T, T1, T2:
You can provide a domain with slots already when creating it:
T := newDomain("3rd", table("myslot" = 42, "anotherSlot" = infinity)): op(T); T::myslot, T::anotherSlot
Object of type DOM_DOMAIN.