Previous Page Next Page Contents

newDomain -- create a new data type (domain)

Introduction

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.

Call(s)

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

Parameters

k - an arbitrary object; typically a string
T - a domain
t - the slots of the domain: a table

Returns

an object of type DOM_DOMAIN.

Further Documentation

The document ``Axioms, Categories and Domains'' is a detailed technical reference for domains.

Related Functions

DOM_DOMAIN, domain, domtype, new, slot

Details

Example 1

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

>> T := newDomain("my-domain")
                                 my-domain

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

>> e := new(T, 42);
   domtype(e)
                            new(my-domain, 42)
      
                                 my-domain

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

>> op(T)
                            "key" = "my-domain"
>> T::key, T::myslot
                             "my-domain", FAIL
>> T::myslot := 42: op(T)
                    "myslot" = 42, "key" = "my-domain"
>> T::myslot^2
                                   1764

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)
                    "myslot" = 42, "key" = "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"):
   op(T2);
   delete T2:
                    "myslot" = 42, "key" = "my-domain"

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:
   op(T);
   op(T1);
                               "key" = "1st"
      
                               "key" = "1st"
>> T1::mySlot := 42:
   op(T);
   op(T1);
                       "mySlot" = 42, "key" = "1st"
      
                       "mySlot" = 42, "key" = "1st"

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);
                       "mySlot" = 42, "key" = "1st"
      
          "anotherSlot" = infinity, "mySlot" = 42, "key" = "2nd"
>> 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)):
   op(T);
   T::myslot, T::anotherSlot
          "key" = "3rd", "anotherSlot" = infinity, "myslot" = 42
      
                               42, infinity
>> delete T:

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000