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.
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 parameters, telephone, and address.
category: acquainted (telephone,
address
): { relative (propinquity
),
workfellow (position,
function
)
};
Execute the queries.
$printR*(, = category: relative); $printR*(, "-----", = : acquainted: (telephone, propinquity)); $printR*(, "-----", = category: ~ : workfellow);
Report window will have three equal Z descriptions separated by the "-----"; string.
category ($Contents
): acquainted (address,
telephone,
$Contents
): relative (propinquity
);
Additional test:
$printL*(, "category: *"); = category: *;
Result:
category: *
category: acquainted (address,
telephone,
$Contents
);
Considered structure:
R (R0 (A: a: …, …): R1 (A1: a1: …, …): R2 (A2: a2: …, …): …, ...): …
Notice that R0 defines primary key attribute of R0 (A: a: …, …), R0: R1 (A1: a1: …, …), R0: R1: R2 (A2: a2: …, …), … relations, and foreign key attribute of R: (R0: R1: R2: …, …) relation.
Remember contents of the workfellow (address, telephone) relation, see the 1.8 Exporting... section. Let us create more comprehensive object (category:, telephone, address) relation. The category had been defined before. The following fragment inputs only new data that Gor Martina is relative, and tests it. The rest will be make in the next sections.
object: Gor Martina = (category: relative); = object: (category: (propinquity)); $printC*(, object: (category: (address)) ); $printC*(, object: (category: (address):) );
It outputs Z descriptions. Last two sentences reflect feature of using of address inheritance in category.
object: Gor Martina (category: acquainted: relative
);
object;
object: Gor Martina;
Considered structure:
R: [R1: …] - R class namely meaning of the R1 class … . For example: R: [R1: r1, R1] leads to R:
r1.
R: =/~ R1: - R class equal/unequal to R1 class. Relations of R1 and R1: meanings are copied to (removed
from) R and R: identical meanings. Assume that R: {r, r1}, R1 (A1): {r1 (a1), r2 (a2)} are available. Consequently,
the R: = R1: entails R (A1): {r, r1 (a1)}.
Notice that R: ... = : R1: ... construction is the same as R: ..., R1: ..., R: ...: R1: ... sequence, R: ... ~ : R1: ... is the same as R: ..., R1: ..., ~ R: ...: R1: .... See sample of the next section about Z variables.
This remark is important for all the equality expressions =/~, =/~ : except =/~ (…). If equality has context defined a some R class, the context is passed to both left and right parts of equality. For example R: { R1: ~ {: R2:} =: R3 } signifies R: R1: ~ R: R2:, R: R1: =: R: R3:.
We face the need of transmitting workfellow: class relation to object: class relation. Look at workfellow:.
= workf*:; = [workf*:];
Result:
workfellow (address,
telephone,
$Contents
): { Smith Anne (address: 4 Broadway Av,
telephone: 415 506-0111,
telephone: 503 743-5226
),
Smith Robert (address: 10 Seventh Av,
telephone: 415 297-0752
)
};
{ Smith Anne,
Smith Robert
};
Make meanings of the object class initially.
object: [= workf*:]; = [object:];
{ Gor Martina,
Smith Anne,
Smith Robert
};
Now we can copy relations and add category: workfellow attribute.
object: = { = workf*: };
object: [=workf*:] = (: workf*);
$printT*(, object: (category: acquainted: ), object,
:acquainted, telephone, address);
object; category: noted: acquainted; telephone; address Gor Martina; relative; ; Smith Anne; workfellow; 415 506-0111; 4 Broadway Av Smith Anne; workfellow; 503 743-5226; 4 Broadway Av Smith Robert; workfellow; 415 297-0752; 10 Seventh Av
Let's print the class names of the object: meanings.
$printN*(, : [obj*:]);
object workfellow
The old workfellow: class relation should be deleted.
~ workfellow:;
Now we can save information about objects.
$printT*("Ex/Interpreter/Object.tab", obj*:, obj*, : [cat*:], tel*, addr*);
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 instead of $x (…) and $x: … for creating new connections in database. Described Z version conceives that : $x is equal to { $x }.
Example of using multitude:
$xTelephone ~;
$xT* = [= tel*: (: Smith Anne)];
= $xT*;
$xT* ~ [= : 415* (: Smith Anne)];
= $xT*;
$xT* = [ = tel*: (obj*: (cat*: workfellow))
~ tel*: (obj*: Smith Anne)
];
= $xT*;
$printL*(, "IMPORTANT TELEPHONES");
$printL*(, "-415-");
$printN*(, = $xT* = [: 415*]);
$printL*(, "-503-");
$printN*(, = $xT* = [: 503*]);
IMPORTANT TELEPHONES -415- 415 297-0752 -503- 503 743-5226
The concepts used frequent should be saved or marked for the next work sessions.
important: telephone = : $xT*; = important:;
Result:
important: telephone: { 415 297-0752,
503 743-5226
};
The next fragments may be illustration of some multitude independence from database. Let us remove important class from current database by means of $xImportant multitude.
$xImportant = important: ;
~ $xI*;
= { $xI*, "Attainable element of this set" };
= { = $xI*, = "Unattainable concepts" };
Result:
{ important: telephone: { 415 297-0752,
503 743-5226
},
"Attainable element of this set"
};
Now we can create concepts equal to $xImportant in another base.
$printL*(, "Test Database"); $base "Ex/Interpreter/Test" ~; $xI* =; = $xI*;
Test Database
important: telephone: { 415 297-0752,
503 743-5226
};