Z Language:

2. Object Database

2.1. Dissimilarity from relational database

Z language maps related concepts on database and vice versa (no concept's relations as SQL). Connections of the concepts make two type of the set: relation and class. So Z language manipulates with relations and classes. The relations feature the relational database, whereas classes, for example its inheritance, are typical for the object database.

2.2. Multilevel classification

Considered structure:
R (A: a, …): R1 (A1: a1, …): R2 (A2: a2, …): …

Mark that R (A): R1 (A1) expression equals to { R (A): R1 } (A1) and equals to R (A): { R1 (A1) }. The R: {: R1} is allowable, but it is the same as R: R1. Duplicate names are not tolerable, for example R1:R1 causes R1.
It may be useful to know: the R: expression assumes all the level R: R1: R2, …, but R:* only one level R: R1.



Let us classify by Z language the objects of the telephone notebook with necessary properties: telephone, and address.
category: acquainted (property: telephone,
                      property: address
                     ): { relative (property: propinquity
                                   ),
                          workfellow (property: position,
                                      property: function
                                     )
                        };
Execute the queries.
= category: relative;
$pl("-----");
= : acquainted: (property: telephone, property: propinquity);
$pl("-----"); 
= { category: ~ : workfellow };
Report window will have three equal Z descriptions separated by the "-----"; string.
category ( property
         ):acquainted ( property:{ address,
                                   telephone
                                 }
                      ):relative ( property:propinquity
                                 );
Additional test:
$pl("category: *");
$pr(category: *);
Result:
category: *
category:acquainted ( property:{ address,
                                 telephone
                               }
                    );

2.3. Class manipulation

Considered structure:
R / - Value of the R.

R: [ R1 / ] - R class namely value of the R1. The R: { R1 / } expression has other meaning and is equal to the R: R1 / .

R: =/~ R1: - R class is equal/unequal to R1 class. Relations of R1 instances are copied to (removed from) R identical instances.

Assume that R: { r, r1 }, R1 (A1): { r1 (a1), r2 (a2) } are available. Consequently, the R: = R1: entails R (A1): { r, r1 (a1) }.


We face the need of transmitting workfellow: class relation to object: class relation. Look at the workfellow:.
= workfellow: ;
= workfellow / ;
Result:
workfellow ( address,
             telephone
           ):{ Smith Anne ( address:4 Broadway Av,
                            telephone:{ 415 506-0111,
                                        503 743-5226
                                      }
                          ),
               Smith Robert ( address:10 Seventh Av,
                              telephone:400 297-0752
                            )
             };
Smith Anne,
Smith Robert;
Make value of the object class initially.
object: [ = workfellow / ];
= object: ;
object:{ Smith Anne,
         Smith Robert
       };
Now we can copy class relations and add category: workfellow attribute.
object: = workfellow: ;
= object: ;
object: [ workfellow / ] (category: workfellow);
object ( address,
         telephone
       ):{ Smith Anne ( address:4 Broadway Av,
                        telephone:{ 415 506-0111,
                                    503 743-5226
                                  }
                      ),
           Smith Robert ( address:10 Seventh Av,
                          telephone:400 297-0752
                        )
         };
Let's print the class names of the object value.
$pn(: [ object / ]);
object,
workfellow;
The old workfellow class relation should be deleted.
workfellow: ~;
Now we can save information about objects.
$pt($file "Ex/Interpreter/Object.tab",
    object: (category: workfellow ),
    property / );

2.5. Multitude variable

Considered structure:
$mul X =/~ … - X multitude is equal/unequal to … . It includes/excludes concepts to X set.

$mul X ~ . It excludes all concepts from X set.

= $mul X . Expression addresses to concepts in a database equal to X set.

=$mul X ~ . It deletes concepts of X from database.

$mul X = . It creates concepts of X in a current database.

The mul key word is optional and need if any variable of other type with the same name was declared. Type or name of variable must follow immediately after $.

System supposes that concepts of multitude are in a current database and therefore tests its existing only if expression defines its connection or equality. For example contents of $x will be tested in ($x), =$x, $x: , but not in [$x], { $x }, $print($x). Constructions $x (…) and $x: … may be used for creating new connections in database.



Example of using multitude:
$mul x ~;
$x = = tel*: (: Smith Anne);
= $x;
$x ~ tel*: 415*;
= $x;
$x = = { tel*: (obj*: (cat*: workfellow))
         ~ tel*: (obj*: Smith Anne)
       };
= $x;
telephone ( object,
            workfellow
          ):{ 415 506-0111 ( object:Smith Anne
                           ),
              503 743-5226 ( object:Smith Anne
                           )
            };
telephone ( object,
            workfellow
          ):503 743-5226 ( object:Smith Anne
                         );
telephone ( object,
            workfellow
          ):{ 400 297-0752 ( object:Smith Robert
                           ),
              503 743-5226 ( object:Smith Anne
                           )
            };
The concepts used frequent should be saved or marked for the next work sessions.
important = : { = $x: 400* };
$pc(important:);
Result:
important:telephone:400 297-0752;
The following fragment may be illustration of some multitude independence from database.
$pl("Test Database");
$base "Ex/Interpreter/Test" ~;
$x =;
= $x;
{ $x } ~;
= { "---", $x };
= $x;
Result:
Test Database
telephone:{ 400 297-0752,
            503 743-5226
          };
"---",
telephone:{ 400 297-0752,
            503 743-5226
          };
;