Added upstream from http://ftp.icm.edu.pl/pub/loglan/
[loglan.git] / doc / loglanmi.rtf
1 {\rtf1\ansi \deff0\deflang1024{\fonttbl{\f0\froman Times New Roman;}{\f1\froman Symbol;}{\f2\fswiss Arial;}{\f3\fswiss AvantGarde;}{\f4\froman Palatino;}{\f5\froman Bookman;}{\f6\fmodern MS LineDraw;}\r
2 {\f7\fmodern Courier New;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue127;\r
3 \red0\green127\blue127;\red0\green127\blue0;\red127\green0\blue127;\red127\green0\blue0;\red127\green127\blue0;\red127\green127\blue127;\red192\green192\blue192;}{\stylesheet{\s232\ri850\tldot\tx8504\tqr\tx8640 \fs20\lang1036 \sbasedon0\snext0 toc 1;}{\r
4 \s242\tqc\tx4252\tqr\tx8504 \fs20\lang1036 \sbasedon0\snext242 footer;}{\s243\tqc\tx4252\tqr\tx8504 \fs20\lang1036 \sbasedon0\snext243 header;}{\s254\sb840\sa480\keepn \b\f5\fs28\lang1036 \sbasedon2\snext0 heading 1;}{\fs20\lang1036 \snext0 Normal;}{\r
5 \s2\sb840\sa480\keepn \f5\fs28\lang1036 \sbasedon0\snext2 section;}{\s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033 \sbasedon0\snext3 program;}{\s4\qj \f5\lang1033 \r
6 \sbasedon0\snext4 zwykly;}}{\info{\title Micro manual of Loglan'82}{\author Andrzej Salwicki}{\operator Andrzej Salwicki}{\creatim\yr1993\mo8\dy12\hr21\min1}{\revtim\yr1994\mo3\dy21\hr17\min55}{\printim\yr1994\mo3\dy21\hr17\min51}{\version34}{\edmins1094}\r
7 {\nofpages40}{\nofwords9800}{\nofchars68634}{\vern16504}}\paperw12242\paperh15842\margl1701\margr1701\margt1361\margb1361\gutter0 \facingp\widowctrl\ftnbj\hyphhotz357\margmirror \sectd \linex0\headery709\footery709\colsx709\endnhere\titlepg {\headerl \r
8 \pard\plain \s243\brdrb\brdrdb\brdrw15\brsp20 \tqc\tx4252\tqr\tx8789 \fs20\lang1036 {\field{\*\fldinst PAGE}{\fldrslt 34}}\tab A.Kreczmar\tab Nov.1990\r
9 \par }{\headerr \pard\plain \s243\brdrb\brdrdb\brdrw15\brsp20 \tqc\tx4252\tqr\tx8789 \fs20\lang1036 \tab Loglan'82\tab {\field{\*\fldinst PAGE}{\fldrslt 33}}\r
10 \par }\pard\plain \fs20\lang1036 {\plain \f5\lang1036 \r
11 \par }{\plain \f5\lang1036 \r
12 \par }{\plain \f5\lang1036 \r
13 \par }{\plain \f5\lang1036 \r
14 \par }{\plain \f5\lang1036 \r
15 \par }{\plain \f5\lang1036 \r
16 \par }\pard \li4537 {\f5\fs28 A micro-manual\r
17 \par }{\f5\fs28 \r
18 \par }{\f5\fs28 of\r
19 \par }{\f5\fs28 \r
20 \par }{\f5\fs28 the programming language\r
21 \par }{\f5\fs28 \r
22 \par }{\f5\fs28 \r
23 \par }{\f5\fs28 \r
24 \par }\pard {\plain \f5\lang1036 \r
25 \par }\pard \li709 {\f5\fs44 L O G L A N - 82\r
26 \par }\pard \li709 {\plain \f5\lang1036 \r
27 \par }\pard \li709 {\f5\fs28 Basic constructs and facilities\r
28 \par }\pard \li709 {\plain \f5\lang1036 \r
29 \par }{\plain \f5\lang1036 \r
30 \par }{\plain \f5\lang1036 \r
31 \par }{\plain \f5\lang1036 \r
32 \par }{\plain \f5\lang1036 \r
33 \par }{\plain \f5\lang1036 \r
34 \par }{\plain \f5\lang1036 \r
35 \par }{\plain \f5\lang1036 \r
36 \par }{\plain \f5\lang1036 \r
37 \par }{\plain \f5\lang1036 Author: Antoni Kreczmar\r
38 \par }\pard {\plain \f5\lang1036 \r
39 \par }{\plain \f5\lang1036 \r
40 \par }{\plain \f5\lang1036 \r
41 \par }{\plain \f5\lang1036 \r
42 \par }{\plain \f5\lang1036 \r
43 \par }{\plain \f5\lang1036 \r
44 \par }{\plain \f5\lang1036 \r
45 \par }{\plain \f5\lang1036 \r
46 \par }{\plain \f5\lang1036 \r
47 \par }{\plain \f5\lang1036 \r
48 \par }{\plain \f5\lang1036 \r
49 \par }{\plain \f5\lang1036 \r
50 \par }\pard \qc\brdrt\brdrs\brdrw30\brsp20 {\plain \f5\lang1036 Institute of Informatics, Warsaw University\r
51 \par }\pard \qc {\plain \f5\lang1036 March 1990\r
52 \par }{\plain \f5\lang1036 edited by A.Salwicki LITA Pau  November 1990\r
53 \par }{\plain \f5\lang1036 \r
54 \par }\pard\plain \s232\ri851\sb840\sa480\tldot\tx8504\tqr\tx8640 \fs20\lang1036 {\b\fs28 Table of contents\r
55 \par }\pard \s232\ri850\tldot\tx8504\tqr\tx8640 {\plain \f5\lang1036 \r
56 \par }{\plain \f5\lang1036 \r
57 \par }{\field\fldedit{\*\fldinst {\plain \f5\lang1036 TOC \\o}}{\fldrslt {\plain \f5\lang1036 1. Compound statements\tab   4\r
58 \par }{\plain \f5\lang1036 2. Modularity\tab   8\r
59 \par }{\plain \f5\lang1036 3. Procedures and functions\tab 10\r
60 \par }{\plain \f5\lang1036 4. Classes\tab 13\r
61 \par }{\plain \f5\lang1036 5. Adjustable arrays\tab 16\r
62 \par }{\plain \f5\lang1036 6. Coroutines and semicoroutines\tab 19\r
63 \par }{\plain \f5\lang1036 7. Prefixing\tab 22\r
64 \par }{\plain \f5\lang1036 8. Formal types\tab 28\r
65 \par }{\plain \f5\lang1036 9. Protection techniques\tab 29\r
66 \par }{\plain \f5\lang1036 10. Programmed deallocation\tab 30\r
67 \par }{\plain \f5\lang1036 11.  Exception handling\tab 32\r
68 \par }{\plain \f5\lang1036 12. Concurrent processes.\tab 3}{\plain \f5\lang1036 3\r
69 \par }{\plain \f5\lang1036 References.\tab 4}{\plain \f5\lang1036 0}{\plain \f5\lang1036 \r
70 \par }\pard\plain \s4\qj \f5\lang1033 }}\pard\plain \s4\qj \f5\lang1033 \page LOGLAN-82 is a universal programming language designed at the Insti\-tu\-te of Informatics, University of Warsaw. Its syntax is patterned upon Pas\-\r
71 cal's. Its rich semantics includes the classical constructs and facili\-ties offe\-red by the Algol-family programming languages as well as more modern facilities, such as concurrency and exception handling.\r
72 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036 The basic constructs and facilities of the LOGLAN-82 programming lan\-gua\-ge include:\r
73 \par }\pard \qj\sb120 {\plain \f5\lang1036 1)  A convenient set of structured statements,\r
74 \par }\pard\plain \s4\qj \f5\lang1033 2)  Modularity (with the possibility of module nesting and extending),\r
75 \par \pard\plain \qj\sb120 \fs20\lang1036 {\plain \f5\lang1036 4) Classes (as a generalization of records) which enable to define  complex structured types, data structures, packages, etc.,\r
76 \par }\pard \qj\sb120 {\plain \f5\lang1036 5) Adjustable arrays whose bounds are determined at run-time in such a  way that multidimensional arrays may be of various shapes, e.g.  triangu\-lar, k-diagonal, streaked, etc.,\r
77 \par }\pard \qj\sb120 {\plain \f5\lang1036 6)  Coroutines and semi-coroutines,\r
78 \par }\pard \qj\sb120 {\plain \f5\lang1036 7) Prefixing - the facility borrowed from Simula-67, substantially  generali\-zed in LOGLAN-82 }{\plain \f5\lang1036 \r
79 - which enables to build up hierarchies of  types and data structures, problem-oriented languages, etc.,\r
80 \par }\pard \qj\sb120 {\plain \f5\lang1036 8)  Formal types treated as a method of module parametrization,\r
81 \par }{\plain \f5\lang1036 9)  Module protection and encapsulation techniques,\r
82 \par }\pard \qj\sb120 {\plain \f5\lang1036 10) Programmed deallocator - a tool for efficient and secure garbage col\-lection, which allows the user to implement the optimal strategy of sto\-rage ma\-nagement,\r
83 \par }\pard \qj\sb120 {\plain \f5\lang1036 11) Exception handling which provides facilities for dealing with   run-time errors and other exceptional situations rai}{\plain \f5\lang1036 sed by the   user,\r
84 \par }{\plain \f5\lang1036 12) Concurrency easily adaptable to any operating system kernel and al\-lo\-wing parallel programming in a natural and efficient way.\r
85 \par }\pard \qj\sb120 {\plain \f5\lang1036  The language covers system programming, data processing, and nume\-ri\-cal computations. Its constructs represent the state-of-art and are effi\-ciently implementable. Large systems consisting of many cooperating mo\r
86 \-dules are easily decomposed and assembled}{\plain \f5\lang1036 , due to the class concept and prefixing.\r
87 \par }\pard \qj {\plain \f5\lang1036  LOGLAN-82 constructs and facilities have appeared and evo}{\plain \f5\lang1036 lved simul\-\r
88 taneously with the experiments on the first pilot compiler (implemented on Mera-400 Polish minicomputer).  The research on LOGLAN-82 imple\-men\-tation engendered with new algorithms for static semantics, context ana\-lysis, code generation, data }\r
89 {\plain \f5\lang1036 structures for storage management etc.\r
90 \par }\pard \qj {\plain \f5\lang1036 The LOGLAN-82 compiler provides a keen analysis of syntactic and se\-mantic errors at compilation as well as at run time. The object code is ve\-ry efficient with respect to time and space. The completeness of error ch}\r
91 {\plain \f5\lang1036 eck\-ing guarantees full security and ease of program debugging.\r
92 \par }\pard\plain \s254\sb840\sa480\keepn \b\f5\fs28\lang1036 1. Compound statements\r
93 \par \pard\plain \s4\qj \f5\lang1033  Compound statements in LOGLAN-82 are built up from simple statements (like assignment statement e.g. x:=y+0.5, call statement e.g. {\b call} P(7,x+5) etc.) by means of conditional, iteration and case statements.\r
94 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036   The syntax of conditional statement is as follows:\r
95 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033    {\b if} boolean expression\line    {\b then}   \line      sequence of statements\line    {\b else}  \line \r
96      sequence of statements\line    {\b fi}  \r
97 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 where "else part" may be omitted:\r
98 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033    {\b if} boolean expression \line    {\b then}  \line      sequence of statements\line    {\b fi} \r
99 \par \pard\plain \s4\qj \f5\lang1033  The semantics of conditional statement is standard. The keyword fi allows to nest conditional statements without appearence of "dangling else" ambi\-guity.\r
100 \par \pard \s4\qj \r
101 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 Example:\r
102 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b if} delta>0    \line   {\b then}  \line     x2:=sqrt(delta)/a/2;\line     {\b if} b=0  \line     {\b then} \line \r
103       x1:=x2\line     {\b else} \line       x1:=-b/a/2+x2; x2:=x1-2*x2\line     {\b fi} \line   {\b else} \line     {\b if} delta=0  \line     {\b then} \line       x1:=-b/a/2; x2:=x1\line     {\b else} \line       write(" no real roots")\line     {\b fi}\r
104  \line   {\b fi}  \r
105 \par \pard\plain \s4\qj \f5\lang1033  The statements in a sequence of statements are separated with semicolons (semicolon may end a sequence , and then, the last statement in the sequence is the empty statement).\r
106 \par  The short circuit control forms are realized in LOGLAN-82 by the conditional statements with orif (or andif) list. A conditional  statement with orif list has the form:        orif \r
107 \par \pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b if} wb1 {\b orif} wb2 ... {\b orif} wbk  \line   {\b then} \line     sequence of statements\line   {\b else}\line \r
108     sequence of statements\line   {\b fi} \r
109 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 and corresponds somehow to a conditi}{\plain \f5\lang1036 onal statement:\r
110 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b if} wb1 {\b or} wb2 ... {\b or} wbk  \line   {\b then}  \line     sequence of statements\line   {\b else}  \line \r
111     sequence of statements\line   {\b fi}  \r
112 \par \pard\plain \s4\qj \f5\lang1033  The above conditional statement (without orif list) selects for  execution one of two sequences of statements, depending on the truth value of the boolean expression:\r
113 \par \pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033 wb1 {\b or} wb2 {\b or} ... wbk   \r
114 \par \pard\plain \s4\qj \f5\lang1033 which is always evaluated till the end. For the execution of the conditional statement with orif list the specified conditons wb1,...,wbk are evaluated in succession, until the fir\r
115 st one evaluates to true. Then the rest of the sequence wb1,...,wbk is abandoned and "then part" is executed. If none of the conditions wb1,...,wbk evaluates to true "else part" is executed (if any).\r
116 \par \pard \s4\qj   Conditional statements with orif list facilitate to program those con_ditions, which evaluation to the end may raise a run-time error.\r
117 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 Example:\r
118 \par }{\plain \f5\lang1036   The execution of the statement:\r
119 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033 {\b if} i>n {\b or} A(i)=0 {\b then} i:=i-1 {\b else} A(i):=1 {\b fi} \r
120 \par \pard\plain \s4\qj \f5\lang1033 where the value of i  is greater than  n, and A is an array with upper bound n, will raise the run-time error. Then the user can write:\r
121 \par \pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033 {\b if} i>n {\b orif} A(i)=0 {\b then} i:=i-1 {\b else} A(i):=1 {\b fi}\r
122 \par \pard\plain \s4\qj \f5\lang1033 what  allows to avoid this run-time error and probably agrees with his intension.  \r
123 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036   Conditional statement with andif list has the form:\r
124 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b if} wb1 {\b andif} wb2 ...  {\b andif} wbk\line   {\b then}  \line     sequence of statements\line   {\b else}  \line \r
125     sequence of statements\line   {\b fi}  \r
126 \par \pard\plain \s4\qj \f5\lang1033  For the execution of this kind of statements, the conditions wb1,...,wbk are evaluated in succession, until the first one evaluates to false; then "else part" (if any) is executed. Otherwise "then part" is executed.\r
127 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 Iteration statement in LOGLAN-82 has the form:\r
128 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033 {\b do} sequence of statements {\b od}\r
129 \par \pard\plain \s4\qj \f5\lang1033 An iteration statement specifies repeated execution of the sequence of statements and terminates with the execution of the simple statement exit\r
130 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 \line Example:\r
131 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   s:=1; t:=1; i:=1;\line   {\b do}  \line     i:=i+1; t:=t*x/i;\line     {\b if} abs(t) < 1.0E-10 {\b then exit fi}; \line \r
132     s:=s+t\line   {\b od};  \r
133 \par \pard\plain \s4\qj \f5\lang1033  If two iteration statements are nested, then double exit in the  inner one terminates both of them.\r
134 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 Example:\r
135 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033 r,x:=0;\line {\b do}  \line   s,t:=1; i:=1; x:=x+0.2;\line   {\b do}    \line     i:=i+1; t:=t*x/i;\line     {\b if} i > n {\b \r
136 then exit exit fi}; (* termination of both loops *)  \line     {\b if} t < 1 {\b then exit fi};      (* termination of the inner loop *)\line     s:=s+t\line   {\b od    \line od}  \r
137 \par \pard\plain \s4\qj \f5\lang1033  In the example above simultaneous assignment statements are illustrated (e.g. r,x:=0) and comments, which begin with a left parenthesis immedi\-ately followed by an asterisk and end with an asterisk immediately fol\-\r
138 lowed by a right parenthesis.\r
139 \par \pard \s4\qj  Triple exit terminates three nested iteration statements, four exit termi\-nates four nested iteration statements etc.\r
140 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 The iteration statement with while condition:  while  \r
141 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b while} boolean expression \line   {\b do}  \line     sequence of statements\line   {\b od}  \r
142 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 is equivalent to:\r
143 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b do}  \line     {\b if not} boolean expression {\b then  exit  fi}; \line     sequence of statements\line   {\b od}  \r
144 \r
145 \par \pard\plain \s4\qj \f5\lang1033  The iteration statements with controlled variables (for statements)  have the forms:\r
146 \par \pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b for} j:=wa1 {\b step} wa2 {\b to} wa3  \line   {\b do}  \line     sequence of statements\line   {\b od } \r
147 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 or\r
148 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b for} j:=wa1 {\b step} wa2 {\b downto} wa3 \line   {\b do}  \line     sequence of statements\line   {\b od}  \r
149 \par \pard\plain \s4\qj \f5\lang1033  The type of the controlled variable j must be discrete. The value of this variable in the case of the for statement with to is increased, and in the case of the for statement with downto is decreased. The\r
150   discrete range begins with the value of wa1 and changes with the step equal to the value of wa2. The execution of the for statement with to terminates when the value of j for the first time becomes g\r
151 reater than the value of wa3 (with downto when the value of j for the first time becomes less than the value of wa3). After the for statement termination the value of its controlled vari\-able is determined and equal to the first value exceeding the spec\r
152 ified dis\-crete range. The values of expressions wa1, wa2 and wa3 are evaluated once, upon entry to the iteration statement. Default value of wa2 is equal 1 (when the keyword step and expression wa2 are omitted).\r
153 \par \pard \s4\qj   For or while statements may be combined with exit statement. \r
154 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 \line Example:\r
155 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b for} j:=1 {\b to} n\line   {\b do} \line      {\b if} x=A(j) {\b then exit fi}; \line   {\b od}  \r
156 \par \pard\plain \s4\qj \f5\lang1033  The above iteration statement terminates either for the least j, 1<=j<=n, such that x=A(j) or for j=n+1 when x=/=A(j), j=1,...,n.\r
157 \par \pard \s4\qj \r
158  To enhance the user's comfort, the simple statement repeat is provided. It may appear in an iteration statement and causes the current iteration to be finished and the next one to be continued (something like jump to CONTINUE in Fortran's DO statements).\r
159 \r
160 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 Example:\r
161 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   i:=0;  s:=0;\line   {\b do}  \line     i:=i+1;\line     {\b if} A(i)<0 {\b then repeat fi}\r
162 ; (* jump to od,iterations are contd.*)\line     {\b if} i > m {\b then exit fi};    (* iteration statement is terminated*) \line     s:=s+sqrt(A(i));\line   {\b od};  \r
163 \par \pard\plain \s4\qj \f5\lang1033  Just as exit, repeat may appear in for statement or while statement. Then the next iteration begins with either the evaluation of a new value of the controlled variable (for statement) or  with the\r
164   evaluation of the condition (while statement). \r
165 \par \pard \s4\qj   Case statement in LOGLAN-82 has the form:\r
166 \par \pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b case} WA  \line     {\b when} L1 : I1    \line     {\b when} L2 : I2    \line     {\b    .}..\line     {\b when} Lk : Ik\r
167     \line     {\b otherwise}  I    \line   {\b esac}  \r
168 \par \pard\plain \s4\qj \f5\lang1033 where WA is an expression , L1,...,Lk are constants and I1,..., Ik,I are se\-quences of statements.\r
169 \par \pard \s4\qj  A case statement selects for execution a sequence of statements Ij, 1{\field{\*\fldinst SYMBOL 163 \\f "Symbol"}{\fldrslt }}j{\field{\*\fldinst SYMBOL 163 \\f "Symbol"}{\fldrslt }}\r
170 k, where the value of WA equals Lj. The choice otherwise covers  all values (possibly none) not given in the previous choices. The execution of a case statement chooses one and only one al\r
171 ternative (since the choices are to be exhaustive and mutually exclusive).\r
172 \par \pard\plain \s254\sb840\sa480\keepn \b\f5\fs28\lang1036 2. Modularity\r
173 \par \pard\plain \s4\qj \f5\lang1033 \r
174  Modular structure of the language is gained due to the large set of means for module nesting and extending. Program modules (units) are blocks, procedures, functions, classes, coroutines and processes. Block is the simplest kind of unit. Its syntax is th\r
175 e following:\r
176 \par \pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b block}  \line     lists of declarations\line   {\b begin}  \line     sequence of statements\line   {\b end}  \r
177 \par \pard\plain \s4\qj \f5\lang1033  The sequence of statements commences with the keyword begin (it may\r
178   be omitted when this sequence is empty). The lists of declarations define the syntactic entities (variables, constants, other units), whose scope is that block. The syntactic entities are identified in the sequence of state\-ments by means of names \r
179 (identifiers).\r
180 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 \line Example:\r
181 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b block}  \line     {\b const} n=250;    \line     {\b var} x,y:real, i,j,k: integer, b: boolean;  \line    {\b  const}\r
182  m=n+1;    \line   {\b begin}  \line     read(i,j);            (* read two integers *)\line     x,y:=n/(i+j);         (* simultaneous assignment *)\line     read(c) ;             (* read a character *)\line     b:= c = 'a';          (* 'a'  a character *)\r
183 \line     {\b for} k:= 1 {\b to} m  \line     {\b do}\line       write(x+y/k:10:4);  (* print the value of x+y/k in the\line         field of  10 characters, 4 digits after the point *)\line     {\b od\line   end } \r
184 \par \pard\plain \s4\qj \f5\lang1033  In the lists of declarations semicolons terminate the whole lists, not the lists elements. Any declaration list must begin with the pertinent keyword (var for variables, const for constants etc.). The\r
185   value of an expression de\-fining a constant must be determinable statically (at compilation time).\r
186 \par \pard \s4\qj   Program in LOGLAN-82 may be  a block or alternatively may  be of the following form:\r
187 \par \pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033    {\b program} name;   \line      lists of declarations\line    {\b begin}   \line      sequence of statements\line    {\b end}\r
188    \r
189 \par \pard\plain \s4\qj \f5\lang1033  Then the whole program can be identified by that name (the source as well as the object code).\r
190 \par \pard \s4\qj  A block can appear in the sequence of statements (of any unit), thus it is a statement. (Main block is assumed to appear as a statement of the given job control language.)\r
191 \par \pard \s4\qj \r
192  For the execution of a block statement the object of block is created in a computer memory, and then, the sequence of statements is performed. The syntactic entities declared in the block are allocated in its object. After a block's termination its objec\r
193 t is automatically deallocated (and the corre\-sponding space may be immediately reused).\r
194 \par \pard \s4\qj  The modular structure of the language works "in full steam" when not only blocks, but the other kinds of units are also used. They will be de\-scribed closer in the following points.\r
195 \par \pard \s4\qj  Unit nesting allows to build up hierarchies of units and supports security of programming. It follows from the general visibility rules; namely, a syn\-\r
196 tactic entity declared in an outer unit is visible in an inner one (unless hidden by an inner declaration). On the other hand, a syntactic entity de\-clared in an inner unit is not visible from an outer one.\line \r
197 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 Example:\r
198 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b program} test;  \line     {\b var} a,b,c:real, i,j,k:integer; \line   {\b begin}  \line     read(a,b,c,i);\line     {\b \r
199 block}    \line       {\b var} j,k:real; \line     {\b begin}    \line       j:=a; k:=j+b; write(" this is the inner block ",j,k)\line     {\b end};    \line     write(" this is the outer block ",i,a:20)\line   {\b end};  \r
200 \par \pard\plain \s4\qj \f5\lang1033 \r
201  In this program, first the main block statement is executed (with variables a,b,c,i,j,k). Next, after the read statement, the inner block statement is executed (with variables j,k). In the inner block the global variables j,k are hidden by the local ones\r
202 .\r
203 \par \pard\plain \s254\sb840\sa480\keepn \b\f5\fs28\lang1036 3. Procedures and functions\r
204 \par \pard\plain \s4\qj \f5\lang1033  Procedures and functions are well-known kinds of units. Their syntax is mo\-del\-led on Pascal's, though with some slight modifications. Procedure (function) declaration consists of a specification part and a body.\tab \r
205 \line \r
206 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 Example:\r
207 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033     {\b unit} Euclid: {\b function}(i,j:integer):integer;  \line     {\b var} k:integer;\line     {\b begin}    \line       {\b \r
208 do}      \line         {\b if} j=0 {\b then exit fi}; \line         k:=i {\b mod} j; i:=j; j:=k  \line       {\b od};      \line       result:=i\line     {\b end};    \r
209 \par \pard\plain \s4\qj \f5\lang1033  Procedure or function specification begins with its identifier preceded by the keyword unit. (The same syntax concerns any other mod\-ul\r
210 e named unit.) Then follows its kind declaration, its formal parameters (if any), and the type of the returned value (only for functions). A body con\-sists of decla\-ration lists for local entities and a sequence of statements. The keyword {\b begin}\r
211  commences the sequence of statements, and is omit\-ted, if this se\-quence is empty. The value returned by a function equals to the most re\-\r
212 cent value of the standard variable "result", implicitly declared in any function. This variable can be used as a local auxiliary variable as well.\r
213 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 \line Example:\r
214 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033     {\b unit} Newton: {\b function}(n,m:integer):integer;   \line     \tab \tab {\b var} i:integer; \line     {\b begin}    \r
215 \line       {\b if} m > n {\b then return fi};  \line       result:=n;\line       {\b for} i:=2 {\b to} m {\b do} result:=result*(n-i+1) {\b div} i {\b od} \line     {\b end} Newton;\r
216 \par \pard\plain \s4\qj \f5\lang1033 \r
217  The optional identifier at the end of a unit must repeat the identifier of a unit. It is suggested that the compilers check the order of unit nesting, so these optional occurrences of identifiers would facilitate program debug\-ging.\r
218 \par \pard \s4\qj  All the local variables of a unit are initialized (real with 0.0, integer with 0, boolean with false etc.). Thus , for instance, the value of function Newton is 0 for m>n, since "result" is also initialized, as any other local variable.\r
219 \r
220 \par \pard \s4\qj   The return statement (return) completes the execution of a procedure (function) body,i.e. return is made to the caller. If return does not appear explicitly, return is made with the execution of the final end\r
221  of a unit. Upon return to the caller the procedure (function) object is deallocated.\r
222 \par \pard \s4\qj  Functions are invoked in expressions with the corresponding list of actual parameters. Procedures are invoked by call statement (also with the corre\-sponding list of actual parameters).\r
223 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 \line Example:\r
224 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033     i:=i*Euclid(k,105)-Newton(n,m+1);\line     {\b call} P(x,y+3);  \r
225 \par \pard\plain \s4\qj \f5\lang1033  Formal parameters are of four categories: variable parameters, procedure parameters, function parameters and type parameters (cf p.8). Variable pa\-\r
226 rameters are considered local variables to the unit. A variable parameter has one of three transmission modes: input, output or inout. If no mode is explicitly given the input mode is assumed. For instance in the unit decla\-ration:\r
227 \par \pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033  {\b unit} P: {\b procedure}(x,y:real,b:boolean;\line             {\b output} c:char,i:integer;{\b inout} :integer);\r
228 \par \pard\plain \s4\qj \f5\lang1033 x,y,b are input parameters , c,i are output parameters , and j is inout pa\-rameter.\r
229 \par \pard \s4\qj  Input parameter acts as a local variable whose value is initialized by the value of the corresponding actual parameter. Output parameter acts as a local variable initialized in the standard manner (\r
230 real with 0.0, integer with 0, boolean with false etc.). Upon return its value is assigned to the corre\-\r
231 sponding actual parameter, in which case it must be a variable. However the address of such an actual parameter is determined upon entry to the body. Inout parameter acts as an input parameter and output parameter together.\r
232 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 \line Example:\r
233 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b unit} squareeq: {\b procedure}(a,b,c:real;{\b output} xr,xi,yr,yi:real); \line \r
234    (* given a,b,c the procedure solves  square equation :\line       ax*x+bx+c=0.\line        xr,xi- real and imaginary part of the first root\line        yr,yi- real and imaginary part of the second root *)\line   {\b var} delta: real;  \line   {\b begin\r
235 }     (*a=/=0*)  \line     a:=2*a; c:=2*c; delta:=b*b-a*c;\line     {\b if} delta <= 0    \line     {\b then}    \line       xr,yr:=-b/a;\line       {\b if} delta=0 {\b then  return fi};     (*xi=yi=0 by default*)  \line       delta:=sqrt(-delta);\line \r
236       xi:=delta/a; yi:=-xi;\line       {\b return      \line     fi};    \line     delta:=sqrt(delta);\line     {\b if} b=0   \line     {\b then}    \line       xr:=delta/a; yr:=-xr;\line       {\b return      \line     fi};    \line     {\b if} b>0 {\b \r
237 then} b:=b+delta {\b else} b:=b-delta {\b fi};\line     xr:=-b/a; yr:=-c/b;\line   {\b end} squareeq;\r
238 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036   A procedure call to the above unit may be the following:\r
239 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b call} squareeq(3.75*H,b+7,3.14,g,gi,h,hi); \r
240 \par \pard\plain \s4\qj \f5\lang1033 where g,h,gi,hi are real variables.\r
241 \par \pard \s4\qj  No restriction  is imposed on the order of declarations. In particular, re\-cursive procedures and functions can be declared without additional an\-nouncements (in contrast to Pascal).\r
242 \par \pard \s4\qj Example:\r
243 \par   For two recursive sequences defined as:\r
244 \par   \tab a(n)=b(n-1)+n+2         n>0\r
245 \par \pard\plain \li567 \fs20\lang1036 {\plain \f5\lang1036   b(n)=a(n-1)+(n-1)*n }{\plain \f5\lang1036     n>0\r
246 \par }{\plain \f5\lang1036   a(0)=b(0)=0\r
247 \par }\pard {\plain \f5\lang1036 one can declare two functions:\r
248 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b unit} a: {\b function}(n:integer):integer;\line   {\b begin}  \line     {\b if} n>0 {\b then} result:=b(n-1)+n+2 {\b fi}\r
249 \line   {\b end} a;  \line   {\b unit} b: {\b function}(n:integer):integer; \line   {\b begin}  \line     {\b if} n>0 {\b then} result:=a(n-1)+(n-1)*n {\b fi} \line   {\b end} b;  \r
250 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 and invoke them:\r
251 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   k:=a(100)*b(50)+a(15);\r
252 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036   Functions and procedures can be formal parameters as well.\r
253 \par }\pard {\plain \f5\lang1036 \line Example:\r
254 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033 {\b unit} Bisec: {\b procedure}(a,b,eps:real;{\b output} x:real;{\b function} \tab \tab \tab \tab \tab \tab \tab \tab \tab \tab \r
255 \tab \tab \tab f(x:real):real);\line (*this procedures searches for zero of the continous function f in \tab \tab \tab \tab \tab \tab \tab \tab \tab \tab \tab \tab the segment (a,b) *)\line {\b var} h:real,s:integer;\line {\b begin}\line   s:=sign(f(a));\r
256 \line   {\b if} sign(f(b))=s {\b then return fi};   (* wrong segment *)  \line   h:=b-a;\line   {\b do}  \line     h:=h/2; x:=a+h;\line     {\b if} h < eps {\b then  return fi};\line     {\b if} sign(f(x))=s {\b then} a:=x {\b else} b:=x {\b fi}\line   {\r
257 \b od}  \line {\b end} Bisec;\r
258 \par \pard\plain \s4\qj \f5\lang1033 In the above declaration, after the input variable parameters a,b,eps and the output variable parameter x, a function parameter f appears. Note that its specification part is complete. Thus the check of actual-formal parame\r
259 \-ter compatibility is possible at compilation time. Making use of this syn\-tactic facility is not possible in general, if a formal procedure (function) is again a formal parameter of a formal procedure (function). The second de\-gree of formal\r
260  procedures (functions) nesting is rather scarce, but LOGLAN-82 admits such a  construct. Then  formal  procedure (function)  has no specification part and the full check of actual-formal parameter compatibility is left to be done at run time.\r
261 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 \line Example:}{\plain \f5\lang1036 \r
262 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b unit} P: {\b procedure}(j:integer; {\b procedure} G (i:integer;\line                                          {\b \r
263 procedure} H));\line     ...\line   {\b begin}  \line     ...\line     {\b call} G(j,P);\line   {\b end} P;   \r
264 \par \pard\plain \s4\qj \f5\lang1033 \r
265  Procedure G is a first degree parameter, therefore it occurs with complete specification part. Procedure H is a second degree parameter and has no specification part. In this case a procedure call can be strongly recursive:\r
266 \par \pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033      {\b call} P(i+10,P); \r
267 \par \pard\plain \s254\sb840\sa480\keepn \b\f5\fs28\lang1036 4. Classes\r
268 \par \pard\plain \s4\qj \f5\lang1033  Class is a facility which covers such programming constructs as struc\-tu\-red type, package, access type, data structure etc. To begin with the pre\-s\-\r
269 entation of this construct, let us consider a structured type assembled from primitive ones:\r
270 \par \pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b unit} bill: {\b class};\line      {\b var}  dollars           :real, \line           not_paid          :boolean,\line \r
271           year,month,day    :integer;\line   {\b end} bill;  \r
272 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036  The above class declaration has the attributes : dollars (real), not_paid (boolean), and year,month,day (integer). Wherever class bill is visibile one can declare variables of type bill:\r
273 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033     {\b var} x,y,z: bill;\r
274 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036 \r
275  The values of variables x, y, z can be the addresses of objects of class bill. These variables are called reference variables. With reference variable one can create and operate the objects of reference variable type.\r
276 \par }\pard \qj {\plain \f5\lang1036  An object of a class is created by the class generation statement (new), and thereafter, its attributes are accessed through dot notation.\r
277 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033     x:={\b new} bill; (* a new object of class bill is created *)\line     x.dollars:=500.5;  (* define amount *)\line \r
278     x.year:=1982;      (* define year *)\line     x.month:=3;        (* define month *)\line     x.day:=8;          (* define day *)\line     y:={\b new} bill;       (* create a new object *)  \line     y.not_paid:=true;  (* bill not_paid *)\line \r
279     z:=y;       (* variable z points the same object as y *)\r
280 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036  If an object of class bill has been created (new bill) and its address has been assigned to variable x (x:=new bill), then the\r
281  attributes of that object are accessible through dot notation (remote access). The expression x.dollars gives , for instance,}{\plain \f5\lang1036  }{\plain \f5\lang1036 \r
282 the remote access to attribute dollars of the object referenced by x. All attributes of class objects are initialized as usual. For the above example the object referenced by x, after the execu\-\r
283 tion of the specified sequence of statements, has the followi}{\plain \f5\lang1036 ng structure:\r
284 \par }\pard \keep {\plain \f7\lang1036 \line       }{\plain \f6\lang1036 \'da\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'bf}{\plain \f7\lang1036 \line       }{\plain \f6\lang1036 \'b3}{\plain \f7\lang1036     500.5    }{\plain \f6\lang1036 \'b3}\r
285 {\plain \f7\lang1036      dollars\line       }{\plain \f6\lang1036 \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4}{\plain \f7\lang1036 \line       }{\plain \f6\lang1036 \'b3}{\plain \f7\lang1036     false    }{\plain \f6\lang1036 \'b3}\r
286 {\plain \f7\lang1036      not_paid\line       }{\plain \f6\lang1036 \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4}{\plain \f7\lang1036 \line       }{\plain \f6\lang1036 \'b3}{\plain \f7\lang1036     1982     }{\plain \f6\lang1036 \'b3}\r
287 {\plain \f7\lang1036      year\line       }{\plain \f6\lang1036 \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4}{\plain \f7\lang1036 \line       }{\plain \f6\lang1036 \'b3}{\plain \f7\lang1036       3      }{\plain \f6\lang1036 \'b3}{\plain \r
288 \f7\lang1036      month\line       }{\plain \f6\lang1036 \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4}{\plain \f6\lang1036 \'b4}{\plain \f7\lang1036 \line       }{\plain \f6\lang1036 \'b3}{\plain \f7\lang1036       8      }{\plain \r
289 \f6\lang1036 \'b3}{\plain \f7\lang1036      day\line       }{\plain \f6\lang1036 \'c0\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'d9}{\plain \f7\lang1036 \r
290 \par }\pard {\plain \f5\lang1036 \line  The object referenced by y and z has the following structure:\r
291 \par }\pard \keep {\plain \f6\lang1036 \line       \'da\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'bf\line }{\plain \f7\lang1036       }{\plain \f6\lang1036 \'b3}{\plain \f7\lang1036       0      }{\plain \f6\lang1036 \'b3}{\plain \f7\lang1036 \r
292      dollars}{\plain \f6\lang1036 \line }{\plain \f7\lang1036       }{\plain \f6\lang1036 \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4\line }{\plain \f7\lang1036       }{\plain \f6\lang1036 \'b3}{\plain \f7\lang1036     true     }{\plain \r
293 \f6\lang1036 \'b3}{\plain \f7\lang1036      not_paid}{\plain \f6\lang1036 \line }{\plain \f7\lang1036       }{\plain \f6\lang1036 \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4\line }{\plain \f7\lang1036       }{\plain \f6\lang1036 \'b3}\r
294 {\plain \f7\lang1036       0      }{\plain \f6\lang1036 \'b3}{\plain \f7\lang1036      year}{\plain \f6\lang1036 \line }{\plain \f7\lang1036       }{\plain \f6\lang1036 \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4\line }{\plain \r
295 \f7\lang1036       }{\plain \f6\lang1036 \'b3}{\plain \f7\lang1036       0      }{\plain \f6\lang1036 \'b3}{\plain \f7\lang1036      month}{\plain \f6\lang1036 \line }{\plain \f7\lang1036       }{\plain \f6\lang1036 \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\r
296 \'c4\'c4\'c4\'c4\'c4\'b4\line }{\plain \f7\lang1036       }{\plain \f6\lang1036 \'b3}{\plain \f7\lang1036       0      }{\plain \f6\lang1036 \'b3}{\plain \f7\lang1036      day}{\plain \f6\lang1036 \line }{\plain \f7\lang1036       }{\plain \f6\lang1036 \r
297 \'c0\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'d9\r
298 \par }\pard \qj {\plain \f5\lang1036   The value none is the default initial value of any reference variable and denotes no objec}{\plain \f5\lang1036 t. A remote access to an attribute of none raises a run time error. \r
299 \par }{\plain \f5\lang1036  Class may have also formal parameters (as procedures and functions). Kinds and transmission modes of formal parameters are the same as in the case of procedures.\r
300 \par }\pard {\plain \f5\lang1036 \line \r
301 \par }\pard {\plain \f5\lang1036 \r
302 \par }{\plain \f5\lang1036 Example:\r
303 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033     {\b unit} node: {\b class} (a:integer);\line      var left,right:node;  \line     {\b end} node; \r
304 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036  Let, for instance, variables z1, z2, z3 be of type node. Then the sequence of statements:\r
305 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033      z1:={\b new} node(5);\line      z2:={\b new} node(3);  \line      z3:={\b new} node(7); \line      z1.left:=z2\r
306 ; z1.right:=z3;\r
307 \par \pard\plain \sa120 \fs20\lang1036 {\plain \f5\lang1036  creates the structure:\r
308 \par }\pard \keep\box\brdrs\brdrw15\brsp20 \dxfrtext180 {\plain \f6\lang1036 \line                    \'da\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'bf\line            }{\plain \f7\lang1036 z1}{\plain \f6\lang1036 \'c4\'c4\'c4\'c4\'c4\'c4\'b4}{\plain \f7\lang1036 \r
309     5   }{\plain \f6\lang1036  \'b3\line                    \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4\line             \'da\'c4\'c4\'c4\'c4\'c4\'c4\'b4}{\plain \f7\lang1036    left }{\plain \f6\lang1036  \'b3\line             \'b3      \'c3\'c4\'c4\'c4\r
310 \'c4\'c4\'c4\'c4\'c4\'c4\'b4\line             \'b3      \'b3 }{\plain \f7\lang1036   right}{\plain \f6\lang1036  \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'bf\line             \'b3      \'c0\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'d9        \'b3\line             \r
311 \'b3                         \'b3\line        \'da\'c4\'c4\'c4\'c4\'c1\'c4\'c4\'c4\'c4\'c4\'bf             \'da\'c4\'c4\'c4\'c4\'c4\'c1\'c4\'c4\'c4\'c4\'bf\line }{\plain \f7\lang1036 z2}{\plain \f6\lang1036 \'c4\'c4\'c4\'c4\'c4\'b4 }{\plain \f7\lang1036 \r
312    3    }{\plain \f6\lang1036  \'b3             \'b3  }{\plain \f7\lang1036    7   }{\plain \f6\lang1036  \'c3\'c4\'c4\'c4\'c4\'c4\'c4}{\plain \f7\lang1036 z3\line }{\plain \f6\lang1036        \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4             \r
313 \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4\line        \'b3  }{\plain \f7\lang1036  none  }{\plain \f6\lang1036  \'b3             \'b3  }{\plain \f7\lang1036   none  }{\plain \f6\lang1036 \'b3 \line    }{\plain \f6\lang1036     \'c3\'c4\'c4\'c4\'c4\r
314 \'c4\'c4\'c4\'c4\'c4\'c4\'b4             \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4\line        \'b3  }{\plain \f7\lang1036  none  }{\plain \f6\lang1036  \'b3             \'b3   }{\plain \f7\lang1036  none  }{\plain \f6\lang1036 \'b3 \line        \r
315 \'c0\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'d9             \'c0\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'d9\r
316 \par }\pard {\plain \f5\lang1036 \line where arrows denote the values of the reference variables.\r
317 \par }\pard \qj {\plain \f5\lang1036  Class may also have a sequence of statements (as any other unit). That sequence can initialize the attributes of the class objects.\r
318 \par }\pard {\plain \f5\lang1036 \line Example:\r
319 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b unit} complex:{\b class}(re,im:real);  \line   {\b var} module:real; \line   {\b begin}  \line \r
320     module:=sqrt(re*re+im*im)\line   {\b end} complex;  \r
321 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036  Attribute module is evaluated for any object gen}{\plain \f5\lang1036 eration of class complex:\r
322 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   z1:={\b new} complex(0,1); (* z1.module equals 1 *) \line   z2:={\b new} complex(2,0); (* z2.module equals 2 *)  \r
323 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036 \r
324  For the execution of a class generator, first a class object is created, then the input parameters are transmitted , and finally, the sequence of statements (if any) is performed. Return is made with the execution of return statement or the final end of \r
325 }{\plain \f5\lang1036 a unit. Upon return the output parameters are transmitted.\r
326 \par }\pard \qj {\plain \f5\lang1036  Procedure object is automatically deallocated when return is ma}{\plain \f5\lang1036 \r
327 de to the caller. Class object is not deallocated , its address can be assigned to a reference variable, and its attributes can be thereafter accessed via this variable. \r
328 \par }{\plain \f5\lang1036  The classes presented so far had only variable attributes. In general, class attributes may be also other syntactic entities, such as  constants, proce\-dures, functions, classes etc. Classes with procedure and function attribu\-\r
329 tes provide a good facility}{\plain \f5\lang1036  to define data structures.\r
330 \par }\pard {\plain \f5\lang1036 \line Example:\r
331 \par }\pard \qj {\plain \f5\lang1036 A push_down memory of integers may be impl}{\plain \f5\lang1036 emented in the following way:\r
332 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b unit} push_down :{\b class};  \line     {\b unit} elem:{\b class}(value:integer,next:elem);\line \r
333      (* elem - stack element *)\line     {\b end} elem;    \line     {\b var} top:elem;    \line     {\b unit} pop: {\b function} :integer;  \line     {\b begin}    \line       {\b if} top=/= {\b none} \line       {\b then}      \line \r
334         result:=top.value; top:=top.next\line      {\b  fi};      \line     {\b end} pop;    \line     {\b unit} push:{\b procedure}(x:integer); (* x - pushed integer *)\line     {\b begin}    \line       top:={\b new} elem(x,top);\line     {\b end} push;\r
335     \line   {\b end} push_down;\r
336 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036  Assume that somewhere}{\plain \f5\lang1036  in a program reference variables of type push_down are declared (of course, in place where push_down is visibile):\r
337 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b var} s,t,z:push_down;  \r
338 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036  Three different push_down memories may be now generated:\r
339 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   s:={\b new} push_down(100); t:={\b new} push_down(911); z:={\b new} push_down(5);  \r
340 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036  One can use these push_down memories as follows:\r
341 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b call} s.push(7); (* push  7 to s *)  \line   {\b call} t.push(1); (* push  1 to t *)   \line \r
342   i:=z.pop;       (* pop an element from z *)\r
343 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036   etc.\r
344 \par }\pard\plain \s254\sb840\sa480\keepn \b\f5\fs28\lang1036 5. Adjustable arrays\r
345 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036  In LOGLAN-82 arrays}{\plain \f5\lang1036 \r
346  are adjustable at run time. They may be treated as objects of specified standard type with index instead of identifier selecting an attribute. An adjustable array should be declare somewhere among the lists of declarations and then may be generated in th\r
347 }{\plain \f5\lang1036 e sequence of state\-ments.\r
348 \par }\pard {\plain \f5\lang1036 \line Example:\r
349 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033  {\b block} \line   {\b var} n,j:integer;  \line   {\b var} A:{\b arrayof} integer;  (* here is the declaration of A *) \line {\r
350 \b  begin \line }  read(n);\line   {\b array} A {\b dim} (1:n);   (* here is the generation of A *) \line   {\b for} i:=1 {\b to} n \line   {\b do}  \line    read(A(i));\line   {\b o}{\b d};  \line   (* etc.*)\line  {\b end} \r
351 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036  A variable A is an array variable. Its value should be the reference to an integer array, i.e. a composite object consisting of integer components each one defined by an integer index. \tab \line \r
352 Array generation statement:\r
353 \par }\pard \qj {\plain \f5\lang1036 \tab  array A dim (1:n);  \r
354 \par }\pard \qj {\plain \f5\lang1036 allocates a one-dimensional integer array with the index bounds 1,n , and assigns its address to variable A. \tab \line The figure below illustrates this situation:\r
355 \par }\pard \keep\box\brdrs\brdrw15\brsp20 \dxfrtext180 {\plain \f6\lang1036 \line         \'da\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'bf              \'da\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'bf\r
356 \par }\pard \keep\box\brdrs\brdrw15\brsp20 \dxfrtext180 {\plain \f6\lang1036         \'b3        \'b3              \'b3 }{\plain \f7\lang1036  A(}{\plain \f7\lang1036 1)  }{\plain \f6\lang1036  \'b3\r
357 \par }\pard \keep\box\brdrs\brdrw15\brsp20 \dxfrtext180 {\plain \f6\lang1036         \'b3        \'b3              \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4\r
358 \par }\pard \keep\box\brdrs\brdrw15\brsp20 \dxfrtext180 {\plain \f6\lang1036         \'b3  }{\plain \f7\lang1036  ... }{\plain \f6\lang1036  \'b3              \'b3  }{\plain \f7\lang1036 A(2)}{\plain \f6\lang1036    \'b3\r
359 \par }\pard \keep\box\brdrs\brdrw15\brsp20 \dxfrtext180 {\plain \f6\lang1036         \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4              \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4\r
360 \par }\pard \keep\box\brdrs\brdrw15\brsp20 \dxfrtext180 {\plain \f6\lang1036         \'b3   }{\plain \f7\lang1036  n }{\plain \f6\lang1036   \'b3              \'b3         \'b3\r
361 \par }{\plain \f6\lang1036         \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4              \'b3   }{\plain \f7\lang1036 ... }{\plain \f6\lang1036   \'b3\r
362 \par }{\plain \f6\lang1036         \'b3    }{\plain \f7\lang1036 j }{\plain \f6\lang1036   \'b3              \'b3         \'b3\r
363 \par }\pard \keep\box\brdrs\brdrw15\brsp20 \dxfrtext180 {\plain \f6\lang1036         \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4              \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4\r
364 \par }\pard \keep\box\brdrs\brdrw15\brsp20 \dxfrtext180 {\plain \f6\lang1036         \'b3    }{\plain \f7\lang1036 A}{\plain \f6\lang1036    \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4   }{\plain \f7\lang1036 A(n)}{\plain \f6\lang1036   \r
365 \'b3\r
366 \par }\pard \keep\box\brdrs\brdrw15\brsp20 \dxfrtext180 {\plain \f6\lang1036         \'c0\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'d9              \'c0\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'d9\r
367 \par }\pard \keep\box\brdrs\brdrw15\brsp20 \dxfrtext180 {\plain \f5\lang1036       }{\plain \f7\lang1036     Block object             Array object\r
368 \par }\pard {\plain \f5\lang1036 \line A general case of array generation statement has}{\plain \f5\lang1036  the form:}{\plain \f7\lang1036 \r
369 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033     {\b array} A {\b dim} (lower:upper)  \r
370 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036 where lower and upper are arithmetic expressions which define the range of the array index.\r
371 \par }\pard {\plain \f5\lang1036 Example:\r
372 \par }{\plain \f5\lang1036  Two-dimensional array declaration :\r
373 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033    {\b var} A: {\b arrayof arrayof} integer;  \r
374 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 and generation:\r
375 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033     {\b array} A {\b dim }(1:n)\line     {\b for} i:=1 {\b to} n {\b do array} A(i) {\b dim} (1:m) {\b od};  \r
376 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 create the structure:\r
377 \par }\pard {\plain \f6\lang1036                                     \'da\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'bf\line                                     \'b3 }{\plain \f7\lang1036 A(1,1)}{\plain \f6\lang1036  \'b3\line                                     \'c3\r
378 \'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4\line                           }{\plain \f6\lang1036           \'b3        \'b3\line                                     \'b3   }{\plain \f7\lang1036 ...}{\plain \f6\lang1036   \'b3\line \r
379                                     \'b3        \'b3\line          \'da\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'bf               \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b3\line          \'b3  }{\plain \f7\lang1036  A(1) }{\plain \f6\lang1036   \'c3\'c4\'c4\r
380 \'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4 }{\plain \f7\lang1036 A(1,m) }{\plain \f6\lang1036 \'b3\line          \'b3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4               \'c0\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'d9\line          \'b3\r
381           \'b3\line          \'b3   }{\plain \f7\lang1036  ... }{\plain \f6\lang1036   \'b3\line          \'b3          \'b3\line          \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4               \'da\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'bf\line \r
382          \'b3   }{\plain \f7\lang1036 A(n) }{\plain \f6\lang1036   \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4 }{\plain \f7\lang1036 A(n,1) }{\plain \f6\lang1036 \'b3\line          \'c0\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'d9\r
383                \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4\line                                     \'b3        \'b3\line   }{\plain \f6\lang1036                                   \'b3   }{\plain \f7\lang1036 ...}{\plain \f6\lang1036   \'b3\line \r
384                                     \'b3        \'b3\line                                     \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4\line                                     \'b3 }{\plain \f7\lang1036 A(n,m) }{\plain \f6\lang1036 \'b3\line \r
385                                     \'c0\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'d9\line }{\plain \f5\lang1036 \r
386 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b block}  \line     {\b var} i,j:integer, A,B: {\b arrayof arrayof} real, n:integer; \line  {\b  begin}  \line     read(n);\r
387 \line     {\b array} A {\b dim} (1:n);  \line     {\b for} i:=1 {\b to} n {\b do} {\b array} A(i) {\b dim} (1:n) {\b od};  \line      (* A is square array *)\line     {\b array} B {\b dim} (1:n);  \line     {\b for} i:=1 {\b to} n {\b do array} B(i) {\b \r
388 dim}(1:i) {\b od}; \line      (* B is lower triangular array *)\line     A(n,n):=B(n,n);\line     B(1):=A(1);\line     B(1):={\b copy}(A(1)); \line   {\b end}  \r
389 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036  Array A is the square array n by n. Each element A(i) , 1}{\field{\*\fldinst {\plain \f5\lang1036 SYMBOL 163 \\f "Symbol"}}{\fldrslt }}{\plain \f5\lang1036 i}{\field{\*\fldinst {\plain \f5\lang1036 \r
390 SYMBOL 163 \\f "Symbol"}}{\fldrslt }}{\plain \f5\lang1036 n contains the address of row A(i,j), 1}{\field{\*\fldinst {\plain \f5\lang1036 SYMBOL 163 \\f "Symbol"}}{\fldrslt }}{\plain \f5\lang1036 j}{\field{\*\fldinst {\plain \f5\lang1036 SYMBOL 163 \\\r
391 f "Symbol"}}{\fldrslt }}{\plain \f5\lang1036 n. Array B is the lower-triangular array. Each element B(i), 1}{\field{\*\fldinst {\plain \f5\lang1036 SYMBOL 163 \\f "Symbol"}}{\fldrslt }}{\plain \f5\lang1036 i}{\field{\*\fldinst {\plain \f5\lang1036 \r
392 SYMBOL 163 \\f "Symbol"}}{\fldrslt }}{\plain \f5\lang1036 n, contains the address of row B(i,j), 1}{\field{\*\fldinst {\plain \f5\lang1036 SYMBOL 163 \\f "Symbol"}}{\fldrslt }}{\plain \f5\lang1036 j}{\field{\*\fldinst {\plain \f5\lang1036 SYMBOL 163 \\\r
393 f "Symbol"}}{\fldrslt }}{\plain \f5\lang1036 i. Thus an ass}{\plain \f5\lang1036 i\-gnment statement A(n,n):=B(n,n) transmits real value B(n,n) to real varia\-\r
394 ble A(n,n). Assignment B(1):=A(1) transmits the address of the first row of A to variable B(1). Finally assignment B(1):=copy (A(1)) creates a copy of the first row of A and assi}{\plain \f5\lang1036 gns its address to B(1).\r
395 \par }\pard \qj {\plain \f5\lang1036  Upper and lower bounds of an adjustable array A are determined by stan\-dard operators lower(A) and upper(A).\r
396 \par }\pard {\plain \f5\lang1036 \line Example:\r
397 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b unit} sort: {\b procedure}(A:{\b arrayof} integer);\line    (*  insertion sort *) \line     {\b var}\r
398  n,i,j:integer; var x:integer; \line   {\b begin}  \line     n:=upper(A);              (* assume lower bound is 1 *)\line     {\b for} i:=2 {\b to} n    \line     {\b do}    \line       x:=A(i); j:=i-1;\line       {\b do}      \line         {\b if}\r
399  x >= A(j) {\b then exit fi};  \line         A(j+1):=A(j);  j:=j-1;\line         {\b if} j=0 {\b then exit fi};\line       {\b od};      \line       A(j+1):=x\line     {\b od};    \line   {\b end} sort;  \r
400 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036   If an array variable A refers to no array its value is equal none (the stan\-\r
401 dard default value of any array variable). An attempt to access an array element (e.g. A(i)) or a bound (e.g. lower(A)), wher}{\plain \f5\lang1036 e A is none, raises a run time error.\r
402 \par }\pard\plain \s254\sb840\sa480\keepn \b\f5\fs28\lang1036 6. Coroutines and semicoroutines\r
403 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036 \r
404  Coroutine is a generalization of class. A coroutine object is an object such that the execution of its sequence of statements can be suspended and reactivated in a programmed manner. Consider first a simple class with a sequence of statements such that a\r
405 }{\plain \f5\lang1036 fter return some non-executed  state\-ments remain. The generation of  its  object terminates with the execution of return statement, although the object can be later reactivated. If}{\plain \f5\lang1036 \r
406  such a class is declared as a coroutine, then its objects may be reactivated. This can be realized by attach statement:\r
407 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   attach(X)  \r
408 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 where X is a reference variable designating the activating coroutine object.\r
409 \par }\pard \qj {\plain \f5\lang1036  In general, since the moment of generation a coroutine object is either ac\-tive or suspended. Any reactivation of a suspended coroutine object X (by attach(X)) causes the active coroutine object to be  suspended and conti\r
410 \-nues the execution of X from th}{\plain \f5\lang1036 e statement following the last execut}{\plain \f5\lang1036 ed one.\r
411 \par }\pard \qj {\plain \f5\lang1036 Main program is also a coroutine. It is accessed through the standard va\-riable main and may be reactivated (if suspended) by the statement     atta\-ch(main). \r
412 \par }\pard {\plain \f5\lang1036 \line Example:\r
413 \par }\pard \qj {\plain \f5\lang1036 \r
414 In the example below the cooperation of two coroutines is presented. One reads the real values from an input device, another prints these values in columns on a line-printer, n numbers in a line. The input stream ends with 0.\r
415 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033 {\b program} prodcons;\line   {\b var} prod:producer,cons:consumer,n:integer,mag:real,last:bool;  \line   {\b unit} producer: {\r
416 \b coroutine}; \line   {\b begin}  \line     {\b return};    \line     {\b do}    \line       read(mag);  (* mag- nonlocal variable, common store *)\line       {\b if} mag=0      \line       {\b then}             (* end of data *)  \line         last:={\r
417 \b true};\line         {\b exit}        \line       {\b fi};      \line       attach(cons);      \line     {\b od};    \line     attach(cons)    \line   {\b end} producer; \line   {\b unit} consumer: {\b coroutine}(n:integer); \line   {\b var} Buf:{\b \r
418 arrayof} real; \line   {\b var} i,j:integer;  \line   {\b begin}  \line     {\b array} Buf {\b dim}(1:n); \line     {\b return};    \line     {\b do}    \line       {\b for} i:=1 {\b to} n      \line       {\b do}      \line         Buf(i):=mag;\line \r
419         attach(prod);        \line         {\b if }last{\b  then exit exit fi}; \line      {\b  od};      \line      {\b  for} i:=1 {\b to} n \line       {\b do}     (* print Buf *)  \line         write(' ',Buf(i):10:2)\line       {\b od};      \line \r
420       writeln;\line     {\b od};    \line     (* print the rest of Buf *)\line     {\b for} j:=1 {\b to} i {\b do} write(' ',Buf(j):10:2) {\b od};  \line     writeln;\line     attach(main);    \line   {\b end} consumer;  \line  {\b begin} \line     prod:=\r
421 {\b new} producer;          \line     read(n);\line     cons:={\b new} consumer(n);   \line     attach(prod);    \line     writeln;\line  {\b end} prodcons; \r
422 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036  The above task could be programmed without coroutines at all. The pre\-sented solution is, however, strictly modular, i.e. one unit realizes the in\-\r
423 put process, another realizes the output process, and both are ready to cooperate with each other.\r
424 \par }\pard \qj {\plain \f5\lang1036  LOGLAN-82  provides also  a facility for  the  semi-coroutine operations. This is gained by the simple statement detach. If X is the active coroutine object, then detach reactivates that coroutine object\r
425  at where the last at\-tach(X) was executed. This }{\plain \f5\lang1036 statement meets the need for the asymetric co\-routine cooperations. (by so it is called semi-coroutine operation). Opera\-\r
426 tion attach requires a reactivated coroutine to be defined explicitly by the user as an actual parameter. Operation detach correspond}{\plain \f5\lang1036 s in some man\-\r
427 ner to return in procedures. It gives the control back to a coroutine object where the last attach(X) was executed, and that coroutine object need not be known explicitly in X. This mechanism is, however, not so secure as the normal control }{\plain \r
428 \f5\lang1036 tr}{\plain \f5\lang1036 ansfers during procedure calls and returns.\r
429 \par }\pard \qj {\plain \f5\lang1036  In fact, the user is able to loop two coroutines traces by :\r
430 \par }\pard \qj {\plain \f5\lang1036    }{\plain \b\f5\lang1036 attach}{\plain \f5\lang1036 (Y) in X       }{\plain \b\f5\lang1036 attach}{\plain \f5\lang1036 (X) in Y   \r
431 \par }{\plain \f5\lang1036 Then }{\plain \b\f5\lang1036 detach}{\plain \f5\lang1036  in X reactivates Y, }{\plain \b\f5\lang1036 detach}{\plain \f5\lang1036  in Y reactivates X. \r
432 \par }\pard \qj {\plain \f5\lang1036  In the example below the application of detach statement is illustrated.\r
433 \par }\pard {\plain \f5\lang1036 Example:\r
434 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033 {\b program} reader_writers; \line \r
435 (* In this example a single input stream consisting of blocks of numbers, each ending with 0, is printed on two printers of different width. The choice of the printer is determined b\r
436 y the block header which indicates the desired number of print columns. The input stream ends with a double 0. m1 - the width of printer_1, m2 - the width of printer_2 *)\line  {\b const} m1=10,m2=20;              \line  {\b var}\r
437  reader:reading,printer_1,printer_2:writing;                                             \line  {\b var} n:integer,new_sequence:boolean,mag:real;                                         \line  \line   {\b  unit} writing:{\b coroutine}(n:integer);   \line \r
438       {\b var} Buf: {\b arrayof} real, i,j:integer;  \line    {\b begin}  \line      {\b array} Buf {\b dim} (1:n);      (* array  generation *)      \line      {\b return};(* return terminates coroutine initialization *)    \line      {\b do} \line \r
439        attach(reader);   (* reactivates coroutine reader *)\line        {\b if} new_sequence       \line        {\b then} \line      (* a new sequence causes buffer Buf to be cleared up *)\line          {\b for} j:=1 {\b to} i {\b do}\r
440  write(' ',Buf(j):10:2) {\b od};\line          writeln;\line          i:=0; new_sequence:=false;  attach(main)  \line        {\b else} \line          i:=i+1;   Buf(i):=mag;\line          {\b if} i=n \line          {\b then} \line            {\b for} j:=1 \r
441 {\b to} n {\b do} write(' ',Buf(j):10:2) {\b od};\line            writeln;\line            i:=0;\line          {\b fi} \line        {\b fi} \line      {\b od} \line    {\b end} writing; \line    {\b unit} reading: {\b coroutine}; \line    {\b begin} \r
442 \line      {\b return}; \line      {\b do} \line        read(mag);\line        {\b if} mag=0  {\b then}  new_sequence:={\b true};   {\b fi}; \line        detach;\line          (* detach returns control to printer_1 or printer_2 \tab \tab \tab \tab \tab \r
443 \tab \tab  depending which one reactivated the reader *)\line      {\b od} \line    {\b end} reading; \line    {\b begin} \line      reader:={\b new} reading; \line      printer_1:={\b new} writing(m1); printer_2:={\b new} writing(m2);\line      {\b do} \r
444 \line        read(n);\line        {\b case} n \line          {\b when} 0:  exit \line          {\b when} m1: attach(printer_1)  \line          {\b when} m2: attach(printer_2)  \line          {\b otherwise}  write(" wrong data"); exit \line  {\b       esac\r
445  \line      od   \line    end};   \r
446 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 \r
447 \par }\pard \qj {\plain \f5\lang1036  Coroutines play the substantial role in process simulation. Class Simula\-tion provided in Simula-67 makes use of coroutines at most degree. LO\-GLAN-82 provides for easy simulation as well. The LOGLAN-82 class Simu\-\r
448 lation is implemented on a heap what giv}{\plain \f5\lang1036 es lg(n) time cost}{\plain \f5\lang1036  (in contrast with O(n) cost of the original implementation). It covers also various simu\-lation  problems of large size and degree of complexity.\r
449 \r
450 \par }\pard\plain \s254\sb840\sa480\keepn \b\f5\fs28\lang1036 7. Prefixing\r
451 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036  Classes and prefixing are ingenius inventions of Simula-67(cf [1]). Unfor\-\r
452 tunately they were hardly ever known and, perhaps, by this have not been introduced into many programming language that gained certain popularity. Moreover, implementa\-tion constra}{\plain \f5\lang1036 \r
453 ints of Simula-67 bind prefixing and classes workableness to such a degree that both faciliti}{\plain \f5\lang1036 \r
454 es cannot be used in all respects. We hope that LOGLAN-82, adopting merits and rooting up deficiencies of these constructs, will smooth their variations and vivify theirs usefulness.\r
455 \par }\pard \qj {\plain \f5\lang1036  What is prefixing ? First of all it is a method for unit extending. Consider the simplest example:\r
456 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b unit} bill: {\b class}; \line      {\b var}   dollars           :real,\line            not_paid          :boolean,\line \r
457            year,month,day    :integer;\line   {\b end} bill; \r
458 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036 Assume the user desires to extend this class with new attributes. Instea}{\plain \f5\lang1036 d of writing a completely new class, he may enlarge the existing one:\r
459 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b unit} gas_bill:bill {\b class}; \line     {\b var} cube_meters: real; \line   {\b end} gas_bill; \r
460 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036 \r
461  Class gas_bill is prefixed by class bill. This new declaration may appear anywhere within the scope of declaration of class bill. (In Simula-67 such a prefixing is forbidden in nested units.) Class gas_bill has all the attributes of class bill and additi\r
462 }{\plain \f5\lang1036 onally its own attributes (in this case the only one: cube_meters). The generation statement of this class}{\plain \f5\lang1036  has the form:\r
463 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033 z:={\b new} gas_bill; \r
464 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036 where z is a reference variable of type gas_bill. Remote access to the attri\-butes of prefixed class is standard:\r
465 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033 z.dollars:=500.5; z.year:=1982; z.month:=3; z.day:=8;\line z.cube_meters:=100000;\r
466 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 \line Consider now the example of a class with parameters.\r
467 \par }\pard {\plain \f5\lang1036 Assume that in a program a class:\r
468 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033 {\b unit} id_card: {\b class}(name:string,age:integer); \line {\b end} id_card; \r
469 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 and its extension:\r
470 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033 {\b unit} idf_card:id card {\b class}(first name:string); \line {\b end} idf_card; \r
471 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 are declared.\r
472 \par }\pard \qj {\plain \f5\lang1036  Then for variabl}{\plain \f5\lang1036 e z of type id_card and variable t of type idf_card the cor\-responding generation statement may be the following:\r
473 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033    z:={\b new} id_card("kreczmar",37); \line    t:={\b new} idf_card("Kreczmar",37,"Antoni"); \r
474 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036 Thus the formal parameters of a class are concatenated with the formal parameters of its prefix.\r
475 \par }\pard \qj {\plain \f5\lang1036 One can still extend class idf_card. For instance:\r
476 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b unit} idr_card:idf_card {\b class}; \line     {\b var} children_number:integer; \line     {\b var} birth_place:string; \r
477 \line   {\b end} idr_card; \r
478 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036  Prefixing allows to build up hierarchies}{\plain \f5\lang1036 \r
479  of classes. Each one hierarchy has a tree structure. A root of such a tree is a class without prefix. One class is a successor of another class iff the first is prefixed by the latter one.\r
480 \par }\pard {\plain \f5\lang1036 \r
481 \par }{\plain \f5\lang1036  Consider the prefix structure:\r
482 \par }\pard \keep {\plain \f7\lang1036                    A\r
483 \par }{\plain \f7\lang1036                  . . .\r
484 \par }{\plain \f7\lang1036                 .  .  .\r
485 \par }{\plain \f7\lang1036                .   .   .\r
486 \par }{\plain \f7\lang1036              B.    .C   .D\r
487 \par }{\plain \f7\lang1036                .\r
488 \par }{\plain \f7\lang1036                 .\r
489 \par }{\plain \f7\lang1036                  .E\r
490 \par }{\plain \f7\lang1036                   .\r
491 \par }{\plain \f7\lang1036                    .\r
492 \par }{\plain \f7\lang1036                     .F\r
493 \par }{\plain \f7\lang1036                    . .\r
494 \par }{\plain \f7\lang1036           }{\plain \f7\lang1036         .   .\r
495 \par }{\plain \f7\lang1036                 G.     .H\r
496 \par }\pard \qj {\plain \f5\lang1036  Class H has a prefix sequence A, B, E, F, H. Let a, b, ... , h denote the cor\-responding unique attributes of classes A, B, ... , H, respectively. The ob\-jects of these classes have the following forms: \r
497 \par }\pard {\plain \f5\lang1036 \r
498 \par }\pard \keep {\plain \f6\lang1036       \'da\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'bf  \'da\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'bf  \'da\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'bf  \'da\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'bf\line       \'b3\r
499      }{\plain \f7\lang1036 a}{\plain \f6\lang1036     \'b3  \'b3     }{\plain \f7\lang1036 a}{\plain \f6\lang1036     \'b3  \'b3     }{\plain \f7\lang1036 a}{\plain \f6\lang1036     \'b3  \'b3     }{\plain \f7\lang1036 a}{\plain \f6\lang1036     \'b3\r
500 \line       \'c0\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'d9  \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4  \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4  \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4\line        }{\plain \f7\lang1036 object A }\r
501 {\plain \f6\lang1036     \'b3     }{\plain \f7\lang1036 b}{\plain \f6\lang1036     \'b3  \'b3     }{\plain \f7\lang1036 c}{\plain \f6\lang1036     \'b3  \'b3     }{\plain \f7\lang1036 d}{\plain \f6\lang1036     \'b3\line                }{\plain \r
502 \f6\lang1036      \'c0\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'d9  \'c0\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'d9  \'c0\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'d9\line                       }{\plain \f7\lang1036 object B}{\plain \f6\lang1036       }\r
503 {\plain \f7\lang1036 object C}{\plain \f6\lang1036       }{\plain \f7\lang1036 object D}{\plain \f6\lang1036 \line       \'da\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'bf  \'da\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'bf  \'da\'c4\'c4\'c4\'c4\'c4\'c4\'c4\r
504 \'c4\'c4\'c4\'bf  \'da\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'bf\line       \'b3     }{\plain \f7\lang1036 a}{\plain \f6\lang1036     \'b3  \'b3     }{\plain \f7\lang1036 a}{\plain \f6\lang1036     \'b3  \'b3     }{\plain \f7\lang1036 a}{\plain \r
505 \f6\lang1036     \'b3  \'b3     }{\plain \f7\lang1036 a}{\plain \f6\lang1036     \'b3\line       \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4  \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4  \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4  \'c3\'c4\r
506 \'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4\line       \'b3     }{\plain \f7\lang1036 b}{\plain \f6\lang1036     \'b3  \'b3     }{\plain \f7\lang1036 b }{\plain \f6\lang1036    \'b3  \'b3     }{\plain \f7\lang1036 b }{\plain \f6\lang1036    \'b3  \'b3     }\r
507 {\plain \f7\lang1036 b}{\plain \f6\lang1036     \'b3\line       \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4  \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4  \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4  \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\r
508 \'c4\'b4\line       \'b3     }{\plain \f7\lang1036 e}{\plain \f6\lang1036     \'b3  \'b3     }{\plain \f7\lang1036 e}{\plain \f6\lang1036     \'b3  \'b3     }{\plain \f7\lang1036 e }{\plain \f6\lang1036    \'b3  \'b3     }{\plain \f7\lang1036 e}{\plain \r
509 \f6\lang1036     \'b3\line       \'c0\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'d9  \'b3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4  \'c3\'c4\'c4\'c4\'c4\'c4}{\plain \f6\lang1036 \'c4\'c4\'c4\'c4\'c4\'b4  \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4\r
510 \line        }{\plain \f7\lang1036 object E}{\plain \f6\lang1036      \'b3     }{\plain \f7\lang1036 f }{\plain \f6\lang1036    \'b3  \'b3     }{\plain \f7\lang1036 f}{\plain \f6\lang1036     \'b3  \'b3     }{\plain \f7\lang1036 f}{\plain \f6\lang1036 \r
511     \'b3\line                     \'c0\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'d9  \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4  \'c3\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'b4\line                       }{\plain \f7\lang1036 object F}{\plain \r
512 \f6\lang1036     \'b3     }{\plain \f7\lang1036 g }{\plain \f6\lang1036    \'b3  \'b3     }{\plain \f7\lang1036 h}{\plain \f6\lang1036     \'b3\line                                   \'c0\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'d9  \'c0\'c4\'c4\'c4\'c4\r
513 \'c4\'c4\'c4\'c4\'c4\'c4\'d9\line }{\plain \f5\lang1036                                    \tab \tab \tab \tab }{\plain \f7\lang1036 object G      object H}{\plain \f5\lang1036 \r
514 \par }\pard {\plain \f5\lang1036 \r
515 \par }\pard \qj {\plain \f5\lang1036 Let Ra, Rb,..., Rh denote reference variables of types A, B,..., H, respecti\-vely. Then the following expressions are correct:\r
516 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   Ra.a,  Rb.b, Rb.a,  Rg.g, Rg.f, Rh.h, Rh.f, Rh.e, Rh.b, Rh.a  etc.\r
517 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036 Variable Ra may designate the object of class B (or C,..., H), i.e. the state\-ment:\r
518 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033    Ra:={\b new} B    \r
519 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036 \r
520 is legal. But then attribute b is not accessible through dot via Ra, i.e. Ra.b is incorrect. This follows from insecurity of such a remote access. In fact, variable Ra may point any object of a class prefixed by A, in particular, Ra may point the object o\r
521 }{\plain \f5\lang1036 f A itself, which has no attribute b. If Ra.b had been correct, a compiler should have distiguish the cases Ra points to the object }{\plain \f5\lang1036 of A or not. But this, of course, is undistinguishable at compilation time.\r
522 \r
523 \par }\pard \qj {\plain \f5\lang1036  To allow, however, the user's access to attribute b (after instruction }{\f7 Ra:=}{\b\f7 new}{\f7  B}{\plain \f5\lang1036 ), the instantaneous type modification is provided within the lan\-guage:\r
524 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033    Ra {\b qua} B \r
525 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036 \r
526  The correctness of this expression is checked at run time. If Ra designates an object of B or prefixed ba B, the type of the expression is B. Otherwise the expression is erroneous. Thus, for instance, the expressions:\r
527 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033    Ra {\b qua} G.b,    Ra {\b qua} G.e    etc. \r
528 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036 enable remote access to the attributes b, c, ... via Ra.\r
529 \par }\pard \qj {\plain \f5\lang1036  So far the question of attribute concatenation was merely discussed. Ho\-wever the sequences of statements can be also concatenated.\r
530 \par }\pard \qj {\plain \f5\lang1036  Consider class B prefixed with class A. In the sequence of statements of class A the keyword inner may occur anywhere, but only once. The se\-\r
531 quence of statements of class B consists of the sequence of statements of class A with inner replaced by the sequ}{\plain \f5\lang1036 ence of statements of class B.\r
532 \par }\pard \keep {\plain \f6\lang1036 \line     }{\plain \b\f7\lang1036 unit}{\plain \f7\lang1036  A :}{\plain \b\f7\lang1036 class}{\plain \f7\lang1036            }{\plain \f7\lang1036          }{\plain \b\f7\lang1036 unit}{\plain \f7\lang1036  B:A }{\plain \r
533 \b\f7\lang1036 class}{\plain \f7\lang1036  \r
534 \par }\pard \keep {\plain \f7\lang1036         ...                                   ...\r
535 \par }\pard \keep {\plain \f7\lang1036     }{\plain \b\f7\lang1036 begin}{\plain \f7\lang1036                                }{\plain \b\f7\lang1036 begin}{\plain \f7\lang1036   \r
536 \par }\pard \keep {\plain \f7\lang1036        ...  }{\plain \f6\lang1036                            \'da\'c4\'c4\'c4}{\plain \f7\lang1036 ...}{\plain \f6\lang1036 \r
537 \par }\pard \keep {\plain \f6\lang1036                                        \'b3                    }{\plain \f7\lang1036            \tab  }{\plain \b\f7\lang1036 inner}{\plain \f6\lang1036  }{\f6\fs18  }{\plain \f6\lang1036  \'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\r
538 \'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4\'c4}{\f6\fs22 \'c4}{\plain \f6\lang1036 \'c4\'c4\'c4\'b4 }{\plain \b\f7\lang1036 inner}{\plain \f6\lang1036  \r
539 \par }\pard \keep {\plain \f6\lang1036                                        \'b3\r
540 \par }\pard \keep {\plain \f6\lang1036        }{\plain \f7\lang1036 ...}{\plain \f6\lang1036                              \'c0\'c4\'c4\'c4...\r
541 \par }\pard \keep {\plain \f6\lang1036     }{\plain \b\f7\lang1036 end}{\plain \f7\lang1036  A;}{\plain \f6\lang1036                               }{\plain \b\f7\lang1036 end}{\plain \f7\lang1036  B; }{\plain \f6\lang1036    \r
542 \par }\pard {\plain \f5\lang1036    \r
543 \par }{\plain \f5\lang1036 \r
544 \par }\pard \qj {\plain \f5\lang1036  In this case inner in class B is equivalent to the empty statement}{\plain \f5\lang1036 . If class B prefixes another class, say C, then inner in B is replaced by the se\-\r
545 quence of statements of class C, and so on.  If inner does not occur expli\-citly, an implicit occurrence of inner before the final end of a class is as\-sumed. \r
546 \par }\pard {\plain \f5\lang1036 \line Example\r
547 \par }\pard {\plain \f5\lang1036  Let class complex be declared as usual:\r
548 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b unit} complex:{\b  class}(re,im:real);  \line   {\b end} complex; \r
549 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036 and assume one desires to declare a class mcomplex with the additional attribute module. In order the generation of class mcomplex define the value of at}{\plain \f5\lang1036 \r
550 tribute module, one can declare a class:\r
551 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b unit} mcomplex:complex {\b class}; \line   {\b var} module:real; \line  {\b  begin} \line     module:=sqrt(re*re+im*im)\r
552 \line   {\b end} mcomplex; \r
553 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036  Class mcomplex may be still extended:\r
554 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b unit} pcomplex:mcomplex {\b class}; \line     {\b var} alfa:real; \line   {\b begin} \line     alfa:=arccos(re/module)\r
555 \line   {\b end} pcomplex; \r
556 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036  For these declarations each generation of class mcomplex defines the va\-lue of attribute module, each generation of class pcomplex defines the va\-lues of attributes module and alfa.\r
557 \par }\pard \qj {\plain \f5\lang1036  For reference v}{\plain \f5\lang1036 ariables z1, z2 z3 of type complex, the following sequence of statements illustrates the presented constructs:\r
558 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   z1:={\b new} complex(0,1);      \line   z2:={\b new} mcomplex(4,7); \line   z3:={\b new} pcomplex(-10,12); \line   {\b if} z2 \r
559 {\b qua} mcomplex.module > 1                  \line   {\b then} \line       z1:=z2;\line   {\b fi}; \line   {\b if} z3 {\b qua} pcomplex.alfa < 3.14  \line   {\b then}  \line      z3.re:=-z3.re;  z3.alfa:=z3.alfa+3.14;\line   {\b fi}; \line   z1 {\b qua}\r
560  mcomplex.module:= 0;  \line   z1.re,z1.im:=0;                                \r
561 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 Example:\r
562 \par }\pard \qj {\plain \f5\lang1036  Binary search tree (Bst) is a bina}{\plain \f5\lang1036 ry tree where for each node x the nodes in the left subtree are less than x, the nodes in the right subtree are grea\-\r
563 ter than x. It is the well-known exercise to program the algorithms for the following operations on Bst:  \tab \r
564 \par }\pard {\plain \f5\lang1036 \tab member(x) = true iff x belongs to Bst\r
565 \par }{\plain \f5\lang1036 \tab insert(x),  enlarge Bst with x, if x does not yet belong to Bst\r
566 \par }{\plain \f5\lang1036 We define both these operations in a class:\r
567 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b unit} Bst: {\b class}; \line     {\b unit} node: {\b class}(value:integer);  (*  tree node  *)  \line       {\b var}\r
568  left,right:node; \line     {\b end} node; \line     {\b var} root:node; \line     {\b unit} help: {\b class}(x:integer);      (* auxiliary class *) \line       {\b var} p,q:node; \line     {\b begin}  \line        q:=root;\line        {\b while}\r
569  q=/= none \line        {\b do} \line          {\b if} x < q.value    \line          {\b then} \line            p:=q; q:=q.left;\line            {\b repeat}  (* jump to the beginning of a loop *)   \line          {\b fi}; \line          {\b if}\r
570  q.value < x \line          {\b then} \line            p:=q; q:=q.right;  {\b repeat} \line          {\b fi}; \line          {\b exit} \line        {\b od}; \line        {\b inner}\line        (* virtual instruction to be\'ffreplaced by the body of\line  \r
571         a module prefixed by help  *)\line     {\b end} help; \line     {\b unit} member:help {\b function}:boolean; \line   (* x is a formal parameter derived from the prefix help *)\line     {\b begin} \line        {\b result}:=q=/=none \line     {\b \r
572 end} member; \line     {\b unit} insert:help {\b procedure}; \line   (* x is a formal parameter derived from the prefix help *)\line     {\b begin}   \line        {\b if} q=/=none {\b then return fi};  \line        q:={\b new} node(x); \line        {\b if\r
573 } p=none {\b then} root:=q; {\b return fi}; \line        {\b if} p.value < x {\b then} p.right:=q {\b else} p.left:=q {\b fi}; \line     {\b end} insert; \line   {\b begin} \line     {\b inner}; \line   {\b end} Bst; \r
574 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036  In the example the common actions of member and insert are program\-\r
575 med in class help. Then it suffices to use class help as a prefix of function member and procedure insert, instead of redundant occurrences of the corresponding sequence of statements in }{\plain \f5\lang1036 both units. \r
576 \par }\pard {\plain \f5\lang1036 Class Bst may be applied as follows:\r
577 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b var} X,Y:Bst; \line   {\b begin} \line        X:={\b new} Bst;  Y:={\b new} Bst; \line        {\b call} X.insert(5); \r
578 \line        {\b if} Y.member(-17) {\b then} .... \line   {\b end} \r
579 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036  As shown in the declaration of Bst, c}{\plain \f5\lang1036 lass may prefix not only other classes but also procedures and functions. Class may prefix blocks as well.\r
580 \par }\pard {\plain \f5\lang1036 \line Example:\r
581 \par }\pard {\plain \f5\lang1036  Let class push_down (p. 5) prefix a block:\r
582 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033    {\b pref} push_down(1000) {\b block} \line    {\b var} ...  \line    {\b begin} \line       ...\line       {\b call}\r
583  push(50); ...  \line       i:=pop;\line       ...\line    {\b end}  \r
584 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036  In the above block prefixed with class push_down one can use pop and push as local attributes. (They are local since the block is embedded in the prefix push down.)\r
585 \par }\pard {\plain \f5\lang1036 \line Example:\r
586 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033    {\b pref} push down(1000) {\b block} \line    {\b begin} \line       ...\line       {\b pref} Bst {\b block} \line       {\b \r
587 begin} \line       (* in this block both structures\line             push down and Bst are visible *)\line         {\b call} push(50); \line         {\b call} insert(13); \line         {\b if} member(10) {\b then} ... \line         i:=pop;\line \r
588         ...\line {\b       end \line    end   \r
589 \par }\pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036 \r
590  In place where classes push_down and Bst are visible together a block prefixed with Bst may be nested in a block prefixed with push_down (or vice versa). In the inner block both data structures are directly accessible. Note that this}{\plain \r
591 \f5\lang1036  construct is illegal in Simula 67. \r
592 \par }\pard\plain \s254\sb840\sa480\keepn \b\f5\fs28\lang1036 8. Formal types\r
593 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036 Formal types serve for unit parametrization with respect to any non-pri\-mitive type.\r
594 \par }\pard {\plain \f5\lang1036 Example:\r
595 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b unit} Gsort:{\b procedure}({\b type} T; A:{\b arrayof} T; {\b function} less\line \tab \tab \tab \tab \tab \tab \tab \r
596  (x, y: T): boolean);\line   {\b var} n,i,j:integer; var x:T; \line   {\b begin } \line     n:=upper(A);\line     {\b for} i:=2 {\b to} n \line     {\b do}   \line       x:=A(i); j:=i-1;\line       {\b do} \line        {\b  if} less(A(j),x) {\b \r
597 then exit fi};   \line         A(j+1):=A(j); j:=j-1;\line         {\b if} j=0 {\b then exit fi};\line       {\b od}; \line       A(j+1):=x;\line     {\b od} \line   {\b end} Gsort; \r
598 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036 \r
599 Procedure Gsort (the generalization of procedure sort from p.4) has type parameter T. A corresponding actual parameter may be an arbitrary non-primitive type. An actual parameter corresponding to A should be an array of elements of the actual type T. Func\r
600 }{\plain \f5\lang1036 tion less should define the linear or\-dering on the domain T.\r
601 \par }\pard \qj {\plain \f5\lang1036  For instance, the array A of type bill (cf p.7) may be sorted with respect to attribute dollars , if the function:\r
602 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b unit} less: {\b function}(t,u:bill):boolean; \line   {\b begin} \line     {\b result}:=t.dollars <= u.dollars\line  {\b \r
603  end} less;\r
604 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 is used as an actual parameter:\r
605 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b call} Gsort(bill,A,less); \r
606 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 If the user desires to sort A with respect to date, it is sufficient to declare :\r
607 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b unit} earlier:{\b function}(t,u:bill):boolean; \line   {\b begin} \line     {\b if} t.year < u.year {\b then result}\r
608 := true; {\b return  fi}; \line     {\b if} t.year=u.year  \line    {\b  then} \line       {\b if} t.month < u.month {\b then result}:=true; {\b return fi}; \line       {\b if} t.month=u.month {\b then result}:=t.day<=u.day  {\b fi} \line     {\b fi}; \r
609 \line    {\b end} earlier; \r
610 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 and to call: call Gsort(bill,A,ea}{\plain \f5\lang1036 rlier); \r
611 \par }\pard\plain \s254\sb840\sa480\keepn \b\f5\fs28\lang1036 9. Protection techniques\r
612 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036 \r
613  Protection techniques ease secure programming. If a program is large, uses some system classes, is designed by a team etc., this is important (and non-trivial) to impose some restrictions on access to non-local attri\-butes.\r
614 \par }\pard \qj {\plain \f5\lang1036  Let us consider a data structure declared as a class. Some of its attributes should be accessible for the class users, the others should not. For ins\-\r
615 tance, in class Bst (p.7) the attributes member and insert are to be acces\-sible. On the other }{\plain \f5\lang1036 hand the attributes root, node and help should not be accessible, even for a meddlesome user. An improper use of them may jeo\-\r
616 pardize the data structure invariants.\r
617 \par }\pard \qj {\plain \f5\lang1036  To forbid the access to some class attributes the three following protection mechanisms are provided:\r
618 \par }\pard {\plain \b\f7\lang1036   close, hidden, }{\plain \f5\lang1036 and}{\plain \b\f7\lang1036  taken. \r
619 \par }\pard \qj {\plain \f5\lang1036  The protection close defined in a class forbids remote access to the speci\-fied attributes. For example, consider the class declaration:\r
620 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b unit} A: {\b class}; \line     {\b close} x,y,z; \line     {\b var}  x: integer, y,z:real; \line     ....\line   {\b end}\r
621  A \r
622 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 Remote access to the attributes x,y,z from outside of A is forbidden.\r
623 \par }\pard \qj {\plain \f5\lang1036 The protection hidden (with akin syntax) does not allow to use the speci\-fied attributes form outside of A neither by the remote access nor in the units prefixed by A. The only way to use a hidden attribute is to use it wi\r
624 \-thin the body of class A.Prote}{\plain \f5\lang1036 ction taken defines these attributes derived from prefix, which the user wishes to use in the prefixed unit. Consider a unit B prefixed by a class A. In unit}{\plain \f5\lang1036 \r
625  B one may specify the attributes of A which are used in B. This protects the user against an unconscious use of an attribute of class A in unit B (because of identifier conflict). When taken list does not occur, then by default, all non-hidden attributes\r
626 }{\plain \f5\lang1036  of class A are accessible in unit B. \r
627 \par }\pard\plain \s254\sb840\sa480\keepn \b\f5\fs28\lang1036 10. Programmed deallocation\r
628 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036   The classical methods implemented to deallocate class objects are based on reference counters or garbage collection. Sometimes the both methods may be combined. A reference counter is }{\plain \r
629 \f5\lang1036 \r
630 a system attribute holding the number of references pointing to the given object. Hence any change of the value of a reference variable X is followed by a corresponding increase or decrease of the value of its reference counter. When the reference counter\r
631 }{\plain \f5\lang1036  becomes equal 0, the object can be deallocated.\r
632 \par }\pard \qj {\plain \f5\lang1036  The deallocation of class objects may also occur during the process of garbage collection. During this process all unreferenced objects are found and removed (while memory may be compactified). In order to}{\plain \r
633 \f5\lang1036  keep the garbage collector able to collect all the garbage, the user should clear all reference variables , i.e. set to None, whenever possible. This system has many disadvantages. First of all, the programmer is forced to clear all refe\-\r
634 rence variables,}{\plain \f5\lang1036  even those which are of auxiliary character. Moreover, garbage collector is a very expensive mechanism and thus it can be used only in emergency cases.\r
635 \par }\pard \qj {\plain \f5\lang1036  In LOGLAN a dual operation to the object generator, the so-called object deallocator is provided. Its}{\plain \f5\lang1036  syntactic form is as follows:\r
636 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033            kill(X)  \r
637 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036 where X is a reference expression. If the value of X points to no object (none) then kill(X) is equivalent to an empty statement. If the\r
638  value of X points to an object O, then after the execution of kill(X), the object O is deallocated. Moreover all ref}{\plain \f5\lang1036 erence variables which pointed to O are set to none. This deallocator provides full }{\plain \i\f5\lang1036 security\r
639 }{\plain \f5\lang1036 , i.e. the attempt to access the deallocated object O is checked and results in a run-time error.\r
640 \par }\pard {\plain \f5\lang1036   For e}{\plain \f5\lang1036 xample:\r
641 \par }\pard\plain \s3\qj\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033       Y:=X;  kill(X);   Y.W:=Z; \r
642 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 causes the same run-time error as:\r
643 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033       X:=none;  X.W:=Z; \r
644 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036 \r
645  The system of storage management is arranged in such a way that the frames of killed objects may be immediately reused without the necessity of calling the garbage collector, i.e. the relocation is performed automati\-\r
646 cally. There is nothing for it but to}{\plain \f5\lang1036  remember not to use remote access to a killed object. (Note that the same problem appears when remote access X.W is used and X=none).  \r
647 \par }\pard {\plain \f5\lang1036 \line \r
648 \par }\pard {\plain \f5\lang1036 \r
649 \par }{\plain \f5\lang1036 E}{\plain \f5\lang1036 xample:\r
650 \par }\pard \qj {\plain \f5\lang1036  Below a practical  example of the programmed deallocation is presented. Consider class Bst (p.7). Let us define a procedure that deallocates the whole tree and is called with the termination of the class Bst.\r
651 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b unit} Bst:{\b class}; \line     (* standard declarations list of  Bst *)\line    {\b unit} kill_all:{\b procedure}\r
652 (p:node); \line    (* procedure kill_all deallocates a tree with root p *)\line    {\b begin} \line      {\b if} p= none {\b then return fi}; \line      {\b call} kill_all(p.left); \line      {\b call} kill_all(p.right);  \line      kill(p) \line    {\b \r
653 end} kill_all; \line    {\b begin \line      inner}; \line      {\b call} kill_all(root)  \line   {\b end} Bst;      \r
654 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 Bst may be applied as a prefix:\r
655 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b pref} Bst {\b block} \line     ...\line   {\b end} \r
656 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036 and automatically will cause the deallocation of the whole tree after return to call kill_all(root) from the prefixed block. \r
657 \par }{\plain \f5\lang1036  To use properly this structure by remote accessing one must call kill_all by himself:\r
658 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b unit} var X,Y:Bst; \line     ...\line   {\b begin} \line      X:={\b new} Bst;  Y:={\b new} Bst; \line         ...\line \r
659      (* after the structures' application *)\line      {\b cal}{\b l} X.kill_all(X.root);  \line      kill(X); \line      {\b call} Y.kill_all(Y.root); \line      kill(Y); \line      ...\line   {\b end} \r
660 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036  Finally note that deallocator kill enables deallocation of array objects, and suspended coroutines and processes as well (cf p.13). \r
661 \par }\pard\plain \s254\sb840\sa480\keepn \b\f5\fs28\lang1036 11.  Exception handling\r
662 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036  Exceptions are events that cause interruption of normal program execu\-\r
663 tion. One kind of exceptions are those which are raised as a result of some run time errors. For instance, when an attempt is made to access a killed object, when the res}{\plain \f5\lang1036 \r
664 ult of numeric operation does not lie within the range, when the dynamic storage allocated to a program is exceeded etc.\r
665 \par }\pard \qj {\plain \f5\lang1036  Another kind of exceptions are those which are raised explicitly by a user (with the execution of the raise statement).\r
666 \par }\pard \qj {\plain \f5\lang1036  The response to exceptions (one or more) is defined by an exception han\-dler. A handler may appear at the end of declarations of any unit. The cor\-\r
667 responding actions are defined as sequences of statements preceded by keyword when and an exception identif}{\plain \f5\lang1036 ier. \r
668 \par }\pard {\plain \f5\lang1036 Ex}{\plain \f5\lang1036 ample:\r
669 \par }\pard \qj {\plain \f5\lang1036  In procedure squareeq (p.3) we wish to include the case when a=0. It may be treated as an exception (division by zero).\r
670 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b unit} squareeq(a,b,c:real;{\b output} xr,xi,yr,yi:real); \line      {\b var} delta:real; \line      {\b handlers} \line \r
671        {\b when} division_by_zero: \line        {\b if} b =/= 0     \line        {\b then}  \line          xi,yr,yi:=0; xr:=-c/b; {\b terminate} \line        {\b else}  \line          {\b raise} Wrong_data(" no roots") \line        {\b fi}; \line   {\b \r
672 end} \line   {\b begin} \line     ...\line   {\b end} squareeq; \r
673 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036  The handler declared in that procedure handles the only }{\plain \f5\lang1036 one exception (division_by_zero).\r
674 \par }\pard \qj {\plain \f5\lang1036 \r
675  When an exception is raised, the corresponding handler is searched for, starting from the active object and going through return traces. If there is no object containing the declaration of the handler, then the program (or the corresponding process) is t\r
676 }{\plain \f5\lang1036 erminated. Otherwise the control is trans\-ferred to the first found handler. \r
677 \par }\pard \qj {\plain \f5\lang1036  In our example the handler is declared within the unit itself, so control is passed to a sequence:\r
678 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b if} b=/=0    ...\r
679 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036  Therefore, when b}{\plain \f5\lang1036 =/=0, the unique root of square equation will be deter\-mined and the procedure will be normally terminated (terminate).   In ge\-\r
680 neral, terminate causes that all the objects are terminated, starting from that one where the exception was raised and ending}{\plain \f5\lang1036  on that one where the handler was found. Then the computation is continued in a normal way.\r
681 \par }\pard \qj {\plain \f5\lang1036  In our example, when b=0, a new exception is raised by the user. For this kind of exceptions , the exception itself should be declared (because it is not predefi}{\plain \f5\lang1036 \r
682 ned as a run time error). Its declaration may have parameters which are transmitted to a handler. The exception declaration need not be visible by the exception handler. However the way the handler is searched for does not differ from the standard one.  C\r
683 }{\plain \f5\lang1036 onsider an example:\r
684 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033   {\b block}\line    {\b signal} Wrong_data(t:string);                       \line    {\b unit} squareeq: \line         ...\r
685 \line    {\b end} squareeq;\line    ...\line  {\b  begin} \line       ...\line   {\b end} \r
686 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036  Exception Wrong_data may be raised wherever its declaration (signal Wrong_data) is v}{\plain \f5\lang1036 \r
687 isible. When its handler is found the specified sequence of actions is performed. In the example above different handlers may be defi\-ned in inner units to the main block where squereeq is called.\r
688 \par }\pard \qj {\plain \f5\lang1036  The case a=0 could be included}{\plain \f5\lang1036 , of course, in a normal way, i.e. by a cor\-\r
689 responding conditional statement occurring in the procedure body. But the case a=0 was assumed to be exceptional (happens scarcely). Thus the eva\-luation of condition a=0 would be mostly unnecessary. As can be n}{\plain \f5\lang1036 \r
690 oticed thanks to exception}{\plain \f5\lang1036 s the above problem can be solved with the minimal waste of run time. \r
691 \par }\pard\plain \s254\sb840\sa480\keepn \b\f5\fs28\lang1036 12. Concurrent processes.\r
692 \par \pard\plain \qj \fs20\lang1036 {\plain \f5\lang1036    Loglan allows to create and execute objects-processes. They can operate simultaneously on different computers linked into a LAN network or a few processes can share one processor (its time-slices).\r
693 \r
694 \par }\pard \qj {\plain \f5\lang1036    Process modules are different from the classes and coroutines for, they use the keyword process. The syntax of process modules is otherwise the same. In a process one can use a few more instructions: resum}{\plain \r
695 \f5\lang1036 e (resume a process which is passive), stop - make the current process passive, etc.  \r
696 \par }\pard \qj {\plain \f5\lang1036  All processes (even those executed on the same computer) are implemen\-ted as distributed, i.e. without any shared memory. This fact implies some restrictions on how processes may be used. Not all restrictions are enfor\-\r
697 ced by the present compiler, so it }{\plain \f5\lang1036 is the programmer's responsibility to respect them. For the details see the User's Manual.\r
698 \par }\pard \qj {\plain \f5\lang1036   Semantics of the generator }{\plain \b\f5\lang1036 new}{\plain \f5\lang1036  is slightly modified when applied to the p}{\plain \f5\lang1036 rocesses. The first parameter of the first process unit in the prefix se\-\r
699 quence must be of type INTEGER. This parameter denotes the node num\-ber of the computer on which this process will be created. For a single computer operation this parameter must be }{\plain \f5\lang1036 equal to 0.\r
700 \par }\pard {\plain \f5\lang1036 \line Example:\r
701 \par }\pard\plain \s3\li567\sb120\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033 {\b unit} A:{\b class}(msg:string);\line ...\line {\b end} A;\line {\b unit} P:A {\b process}(node:integer, pi:real);\line ...\r
702 \line {\b end} P;\line ...\line {\b var} x:P;\line ...\line {\b begin}\line ...\line  (* Create process on node  4.  The  first  parameter  is  the  *) \line  (*string required by the prefix A, the second is the node number *)\line  x := {\b new}\r
703  P("Hello", 4, 3.141592653);\line ...\line {\b end}\r
704 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 \r
705 \par }{\plain \f5\lang1036 \r
706 \par }{\plain \f5\lang1036 \r
707 \par }{\plain \f5\lang1036   COMMUNICATION MECHANISM\r
708 \par }{\plain \f5\lang1036 \r
709 \par }\pard \qj {\plain \f5\lang1036 Processes may communicate and synchronize by a mechanism based on rendez-vous. It will be referred to as "alien call" in the following descrip\-tion.\r
710 \par }\pard {\plain \f5\lang1036 \tab An alien call is either:\tab \r
711 \par }{\plain \f5\lang1036   - a procedure  call performed by a remote access to a process object, or\tab \r
712 \par }{\plain \f5\lang1036   - a call of a procedure which is a formal parameter of a process,  or\tab \r
713 \par }\pard \ri-232 {\plain \f5\lang1036   - a call of a procedure which is a formal parameter of an alien-called pro}{\plain \f5\lang1036 \-ce\-du\-re (this is a recursive definition).\r
714 \par }\pard \qj {\plain \f5\lang1036 Every process object has an enable mask. It is defined as a subset of all procedures declared directly inside a process unit or any unit from its pre\-fix sequence (i.e. subset of all procedures that may be alien-called).\r
715 \r
716 \par }\pard \qj {\plain \f5\lang1036 A procedure is enabled in a process if it belongs to that process' enable mask. A procedure is disabled if it does not belong to the enable mask. \r
717 \par }{\plain \f5\lang1036 Immediately after generation of a process object its enable mask is empty (all procedures are }{\plain \f5\lang1036 disabled).\r
718 \par }\pard \qj {\plain \f5\lang1036 Semantics of the alien call is different from the remote call described in the report. Both the calling process and the process in which the proce\-\r
719 dure is declared (i.e. the called process) are involved in the alien call. This way the alien call may be us}{\plain \f5\lang1036 ed as a synchronization mechanism.\r
720 \par }\pard \qj {\plain \f5\lang1036 The calling process passes the input parameters and waits for the call to be completed.\r
721 \par }\pard \qj {\plain \f5\lang1036 The alien-called procedure is executed by the called process. Execution of the procedure will not begin before certai}{\plain \f5\lang1036 \r
722 n conditions are satisfied. First, the called process must not be suspended in any way. The only exception is that it may be waiting during the ACCEPT statement (see below). Se\-cond, the procedure must be enabled in the called process.\r
723 \par }\pard \qj {\plain \f5\lang1036 When the above two conditions are met the called process is interrupted and forced to execute the alien-called procedure (with parameters passed by the calling process).\r
724 \par }\pard \qj {\plain \f5\lang1036 Upon entry to the alien-called procedure all procedures become disabled in the called process.\r
725 \par }\pard \qj {\plain \f5\lang1036   Upo}{\plain \f5\lang1036 \r
726 n exit the enable mask of the called process is restored to that from before the call (regardless of how it has been changed during the execution of the procedure). The called process is resumed at the point of the inter\-\r
727 ruption. The execution of the ACCE}{\plain \f5\lang1036 PT statement is ended if the called pro\-\r
728 cess was waiting during the ACCEPT (see below). At last the calling process reads back the output parameters and resumes its execution after the call statement.\r
729 \par }\pard \qj {\plain \f5\lang1036   The process executing an alien-called procedure can }{\plain \f5\lang1036 easily be interrupted by another alien call if the enable mask is changed.\r
730 \par }\pard \qj {\plain \f5\lang1036   There are some new language constructs associated with the alien call mechanism. The following statements change the enable mask of a pro\-cess:\tab \r
731 \par }\pard \sb120\sa120 {\plain \f5\lang1036 \tab ENABLE p1, ..., pn\tab \r
732 \par }\pard \qj {\plain \f5\lang1036 enables the procedures with identifiers p1, ..., pn. If there are any proces\-ses waiting for an alien call of one of these procedures, one of them is cho\-\r
733 sen and its request is processed. The scheduling is done on a FIFO basis, so it is strongly fair. The}{\plain \f5\lang1036  statement}{\plain \f5\lang1036 :\tab \r
734 \par }\pard \sb120\sa120 {\plain \f5\lang1036     DISABLE p1, ..., pn \tab \r
735 \par }\pard {\plain \f5\lang1036 disables the procedures with identifiers p1, ..., pn.\r
736 \par }{\plain \f5\lang1036   In addition a special form of the RETURN statement:\tab \r
737 \par }\pard \sb120\sa120 {\plain \f5\lang1036     RETURN ENABLE p1, ..., pn DISABLE q1, ..., qn \tab \r
738 \par }\pard \qj {\plain \f5\lang1036 \r
739 allows to enable the procedures p1, ..., pn and disable the procedures q1,...,qn after the enable mask is restored on exit from the alien-called procedure. It is legal only in  the  alien-called procedures (the legality is not enforced by the compiler).}\r
740 {\plain \f5\lang1036 \r
741 \par }\pard \qj {\plain \f5\lang1036  A called process may avoid busy waiting for an alien call b}{\plain \f5\lang1036 y means of the ACCEPT statement:\tab \r
742 \par }\pard \sb120\sa120 {\plain \f5\lang1036 \tab ACCEPT p1, ..., pn \tab \r
743 \par }\pard \qj {\plain \f5\lang1036 adds the procedures p1, ..., pn to the current mask, and waits for an alien call of one of the currently enabled procedures. After the procedure return the enable mask is restored to that from before the ACCEPT statement.\r
744 \r
745 \par }\pard \qj {\plain \f5\lang1036  Note that the ACCEPT statement alone (i.e. without any ENABLE/DISABLE statements or options) provides a sufficient communi\-\r
746 cation mechanism. In this case the called process may execute the alien-called procedure only during the A}{\plain \f5\lang1036 \r
747 CCEPT statement (because otherwise all procedures are disabled). It means that the enable mask may be forgotten altogether and the alien call may be used as a pure totally synchronous rendez-vous. Other constructs are introduced to make partially asynchro\r
748 }{\plain \f5\lang1036 \-nous communication patterns possible.\r
749 \par }\pard \qj {\plain \f5\lang1036 \r
750 \par }{\plain \f5\lang1036 Below find a complete listing of a simple example - monitors.\r
751 \par }\pard {\plain \f5\lang1036 \r
752 \par }\pard\plain \s3\li567\sb240\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 \f7\fs20\lang1033 {\b program} monitors;\line  \line \r
753 (* this an example showing 5 processes: two of them are in fact monitors, one controls the screen=ekran *)\line \line   {\b unit} ANSI: {\b class};  \line   (* CHECK whether config.sys contains a line\line        device=ansi.sys\line \r
754      the class ANSI enables operations on cursor,\line                        and bold, blink, underscore etc. *) \line                                \line   {\b unit} Bold : {\b procedure};\line   {\b begin}\line     write( chr(27), "[1m")\line   {\b \r
755 end} Bold;\line     \line   {\b unit} Blink : {\b procedure};\line   {\b begin}\line     write( chr(27), "[5m")\line   {\b end} Blink;\line   \line   {\b unit} Reverse : {\b procedure};\line   {\b begin}\line     write( chr(27), "[7m")\line   {\b end}\r
756  Reverse;\line \line   {\b unit} Normal : {\b procedure};\line   {\b begin}\line     write( chr(27), "[0m")\line   {\b en}{\b d} Normal;\line   \line   {\b unit} Underscore : {\b procedure};\line   {\b begin}\line     write( chr(27), "[4m")\line   {\b end\r
757 } Underscore;\line \line   {\b unit} inchar : IIUWgraph {\b function} : integer;\line     (*podaj nr znaku przeslanego z klawiatury *)\line     {\b var} i : integer;\line   {\b begin}\line     {\b do}\line       i := inkey;\line       {\b if} i <> 0 {\b \r
758 then exit fi};\line     {\b od};\line     {\b result} := i;\line   {\b end} inchar;\line   \line   {\b unit }NewPage : {\b procedure};\line   {\b begin}\line     write( chr(27), "[2J")\line   {\b end} NewPage;\line   \line   {\b unit}  SetCursor : {\b \r
759 procedure}(row, column : integer);\line     {\b var} c,d,e,f  : char,\line         i,j : integer;\line   {\b begin}\line     i := row {\b div} 10;\line     j := row {\b mod} 10;\line     c := chr(48+i);\line     d := chr(48+j);\line     i := column {\b \r
760 div} 10;\line     j := column {\b mod} 10;\line     e := chr(48+i);\line     f := chr(48+j);\line     write( chr(27), "[", c, d, ";", e, f, "H")\line   {\b end} SetCursor;        \line {\b end} ANSI;\line \line   \line     {\b unit} monitor:  {\b process}\r
761 (node:integer, size:integer,e: ekran);\line \line        {\b var} buf: {\b arrayof} integer,\line            nr,i,j,k1,k2,n1,n2: integer;\line \line \tab \line     {\b unit }lire: {\b procedure}({\b output} k: integer);\line     {\b begin}\line       {\b \r
762 call} e.druk(13,2+nr*30+k1,0,k2);\line       {\b call} e.druk(13,2+nr*30+(i-1)*6,1,buf(i));\line       k1:=(i-1)*6;\line       k:=buf(i);\line       k2:=k;\line       i:= (i {\b mod} size)+1;\line       {\b if} i=j\line       {\b then}\line         {\b \r
763 call} e.printtext("i equal j")\line       {\b fi}; \line     {\b end} lire;\line     \line     {\b unit} ecrire: {\b procedure}(n:integer);\line     {\b begin\line }      {\b call} e.druk(13,2+nr*30+n1,0,n2);\line       {\b call}\r
764  e.druk(13,2+nr*30+(j-1)*6,2,n);\line       n1:=(j-1)*6;\line       buf(j) := n;\line       n2:=buf(j);\line       j := (j{\b  mod} size)+1;\line       {\b if} i=j\line       {\b then}\line         {\b call} e.printtext("j equal i")\line       {\b fi}; \r
765 \line     {\b end} ecrire;\line   {\b begin}\line     {\b arra}{\b y} buf {\b dim}(1:size);\line     nr := size - 4;\line     {\b for} i := 1 {\b to} size\line     {\b do}\line       buf(i) :=  i+nr*4;\line       {\b call}\r
766  e.druk(13,2+nr*30+(i-1)*6,0,buf(i));\line     {\b od};\line     i:=1;  \line     j := size;\line     k1:=0;\line     k2:=buf(1);\line     n1:=(size-1)*6;\line     n2:=buf(size);\line     (* end initialize buffer *)\line     {\b return};\line     \line \r
767     {\b do}\line     {\b   accept} lire, ecrire\line     {\b od}\line   {\b end} monitor;\line   \line   {\b unit} prcs:  {\b process}(node,nr:integer, mleft,mright:\line \tab \tab \tab \tab \tab \tab \tab  monitor, e: ekran);\line     {\b var}\r
768  l,o: integer;\line \line   {\b begin}\line     {\b call} e.SetCursor(8+(nr-1)*10,29);\line     {\b if} nr = 1\line     {\b then}\line     {\b   call} e.printtext("<-- p1 <--");\line     {\b else}\line       {\b call} e.printtext("--> p2 -->");\line     {\r
769 \b fi;    \line     return;\line     do}\line       {\b call} mleft.lire(l) ;\line       {\b call} e.druk(11+(nr-1)*4,31-(nr-1)*8,1,l);\line       l:= l+1;\line       {\b call} mright.ecrire(l) ; \line       {\b call} e.druk(10+(nr-1)*6,23+(nr-1)*8,2,l);\r
770 \line       {\b if} l {\b mod} 15 = 0 \line       {\b then}\line         o:= e.inchar;\line \tab       {\b if} o = -79 {\b then call endrun fi};\line       {\b fi};\tab \line     {\b od};\line   {\b end }prcs;\line   \r
771 \par \pard \s3\li567\sb240\sa120\tx851\tx1134\tx1418\tx1701\tx1985\tx2268\tx2552\tqdec\tx2835\tqdec\tx3119 {\b unit} ekran : ANSI {\b process}(nrprocesora: integer);\line {\b     unit }printtext{\b : procedure}(s:string);\line     {\b begin}\line \r
772       write(s);\line       {\b call} Normal;\line     {\b end} printtext;\line \line     {\b unit  }druk: {\b procedure}(gdzieW,gdzieK,jak,co:integer);\line     {\b begin}\line   {\b     call} SetCursor(gdzieW,gdzieK);\line       write("   ");\line       \r
773 {\b if} jak=0 {\b then call} Normal {\b else}\line         {\b if} jak=1 {\b then call} Reverse{\b  else}\line           {\b if} jak=2 {\b then call} Bold \line           {\b fi}\line         {\b fi}\line       {\b fi};\line       write(co:3);\line       \r
774 {\b call} Normal;\line  {\b    end} druk;\line \line     {\b unit} print: {\b procedure} (i:integer);\line     {\b begin}\line       write(i:4)\line     {\b end} print;\line   {\b begin\line     return};\line     \line     {\b do accept} inchar, \line \r
775               Normal,NewPage, SetCursor, Bold, Underscore,\line \tab       Reverse, Blink, print, printtext, druk\line     {\b od}\line   {\b end} ekran;\line   \line {\b var} m1,m2:monitor,\line     e:ekran,\line     p1,p2:prcs;\line      \line {\b begin\r
776 }     (* ----- HERE IS THE MAIN PROGRAM ----- *)\line   (* create a  configuration *)\line   e:= {\b new} ekran(0);\line   {\b resume}(e);\line   {\b call} e.Normal;\line   {\b call} e.NewPage;\line   m1 := {\b new} monitor(0,4,e);\line   m2 := {\b new}\r
777  monitor(0,5,e);\line   \line   p1 := {\b new} prcs(0,1,m2,m1,e);\line   p2 := {\b new} prcs(0,2,m1,m2,e);\line     \line   {\b resume}(m1);\line   {\b resume}(m2);\line   {\b resume}(p1);\line   {\b resume}(p2);\line {\b end} monitors;\r
778 \par \pard\plain \s254\sb840\sa480\keepn \b\f5\fs28\lang1036 {\plain \b\f5\lang1036 \page }References.\r
779 \par \pard\plain \fs20\lang1036 {\plain \f5\lang1036 \r
780 \par }\pard Bartol,W.M., et al.{\plain \f5\lang1036 \r
781 \par }{\i Report on the Loglan 82 programming Language,}{\plain \f5\lang1036 \r
782 \par }Warszawa-Lodz, PWN, 1984\r
783 \par \pard {\f5 \r
784 \par }\pard O.-J. Dahl, B. Myhrhaug, K. Nygaard, \line {\i Simula 67 Common Base Language, \line }Norwegian Computing Center, Oslo, 1970           {\plain \lang1036 the mother of object languages!!}\r
785 \par \pard {\f5 \r
786 \par }\pard {\f5 Hoare C.A.R.\line }{\i\f5  Monitors, an operating system structuring concept.\r
787 \par }\pard {\f5 CACM,vol.17,N.10,October 1974,pp.549-57}\r
788 \par \pard \r
789 \par {\i Loglan'82 }\r
790 \par {\i User's guide}\r
791 \par Institute of Informatics, University of Warsaw 1983, 1988\r
792 \par LITA, Universit\'e9 de Pau, 1993\r
793 \par (distributed together with this package)\r
794 \par \r
795 \par A.Kreczmar, A.Salwicki, M. Warpechowski, \r
796 \par {\i Loglan'88 - Report on the Programming Language,}\r
797 \par Lecture Notes on Computer Science vol. 414, Springer Vlg, 1990,\r
798 \par ISBN 3-540-52325-1\r
799 \par \r
800 \par /* if you can read polish, there is a good manual of Loglan   */\r
801 \par A.Szalas, J.Warpechowska,\r
802 \par {\i LOGLAN,   }\r
803 \par Wydawnictwa Naukowo-Techniczne, Warszawa, 1991 ISBN 82-204-1295-1 \r
804 \par      \r
805 \par \pard {\plain \lang1036 see also the Readings file of this distribution.\r
806 \par }{\plain \lang1036 \r
807 \par }}