Added upstream from http://ftp.icm.edu.pl/pub/loglan/
[loglan.git] / HTML / klasyiob.htm
1 <!doctype html public "-//IETF//DTD HTML//EN">\r
2 <HTML>\r
3 \r
4 <HEAD>\r
5 \r
6 <TITLE>Klasy i obiekty</TITLE>\r
7 \r
8 <META NAME="GENERATOR" CONTENT="Internet Assistant for Word 1.0Z">\r
9 <META NAME="AUTHOR" CONTENT="NOM">\r
10 </HEAD>\r
11 \r
12 <BODY>\r
13 \r
14 <H1><IMG SRC="loglanmm.gif" ALIGN="BOTTOM">  Chapter 1: Classes\r
15 and objects</H1>\r
16 \r
17 <P>\r
18 The still growing fascination of object-oriented programming dates\r
19 to 1989 when several software companies offered compilers of object-oriented\r
20 Pascal's, of C (C++ and Objective C) etc. We welcome this recognition\r
21 of merits of object-oriented programming with satisfaction. Let\r
22 us recall that classes and objects have more than 24 years of\r
23 tradition. They appeared in Simula-67. Along the line of R&amp;D\r
24 concerning classes and their objects one can find the results\r
25 achieved at the Institute of Informatics, University of Warsaw.\r
26 We shall present many of them during these lectures.\r
27 <P>\r
28 Notion of object has its roots in the well known structure of\r
29 an Algol and Pascal-like program.\r
30 <P>\r
31 Let us begin with the notion of module. In a program one can indicate\r
32 several modules. The whole program is a module, every procedure\r
33 and function declared in a program is a module too.\r
34 <P>\r
35 In the language Loglan we have more kinds of modules:\r
36 <UL>\r
37 <LI> blocks, \r
38 <LI>procedures, \r
39 <LI>functions, \r
40 <LI>classes, \r
41 <LI>coroutines, \r
42 <LI>processes, \r
43 <LI>modules which serve the exceptions and/or signals - they are\r
44 shortly called handlers.\r
45 </UL>\r
46 \r
47 <P>\r
48 Let us look at the most external module of a program\r
49 <PRE>\r
50       _______________________ \r
51       |<B>program</B> name (...)   |\r
52       |                     |    This a module.\r
53       | &lt;<I>declarations</I>&gt; e.g. |    (It can contain other modules) \r
54       | <B>var</B> x,y:real,a:bool;|\r
55       |                     |\r
56       |<B>begin</B>                |\r
57       |                     |\r
58       | &lt;<I>instructions</I>&gt; e.g. |\r
59       | x:=x+y;             |\r
60       | a:=x*x&lt;y;           |\r
61       | <B>if</B> <B>not</B> a <B>then</B> ...<B>fi</B>;|\r
62       | <B>while</B> ...           |\r
63       | <B>do</B>                  |\r
64       |   ...               |\r
65       | <B>od</B>                  |\r
66       |                     |\r
67       |<B>end</B>                  |\r
68       |_____________________|\r
69 </PRE>\r
70 \r
71 <P>\r
72 During an execution of a program the so called activation record\r
73 of the above module is allocated in a memory. This is a prototype\r
74 of the notion of object.\r
75 <PRE>\r
76     _________________________\r
77     |<I>memory of data</I>         |\r
78     |                       |\r
79     | x real  0.5           |\r
80 R   | y real -1.17          |    This is an activation record,\r
81 A   | a bool  true          |    sometimes called a dynamic ins-\r
82 M   | ..................... |    tance of the (program) module.\r
83     |<I>memory of instructions</I> |\r
84 m   | x:=x+y;               |\r
85 e   | a:=x*x&lt;y;             |\r
86 m   | <B>if</B> <B>not</B> a <B>then</B> ... <B>fi</B>; |\r
87 o   | <B>while</B> ...             |\r
88 r   | <B>do</B>                    |\r
89 y   |   ...                 |\r
90     | <B>od</B>                    |\r
91     |_______________________|\r
92 </PRE>\r
93 \r
94 <P>\r
95 Object-oriented programming develops the above remarks and enriches\r
96 the image the reader could build from them. In particular, object-oriented\r
97 programming requires more frames and assumes a wider spectrum\r
98 of the types of frames. Objects are just one type of frames appearing\r
99 in programming.\r
100 <P>\r
101 More frames! Where they are coming from? Can we recognize them\r
102 in our Pascal practice? Yes, they arise during execution of procedure\r
103 statements. How? They are known under the name of activation records\r
104 or dynamic instances of procedures.\r
105 <P>\r
106 An example, a snapshot of program's execution may look like:\r
107 <P>\r
108 The above picture is a snapshot of an execution of the main program\r
109 taken in the moment when in the main program we executed a <B>call\r
110 </B>g procedure instruction, which caused the creation of an activation\r
111 record for g and its execution, which in turn executed a <B>call\r
112 </B>f procedure instruction, which caused the creation of (1st)\r
113 instance of an activation record for f procedure and ...\r
114 <PRE>\r
115    __________________________________________________\r
116    |                                   ___________  |\r
117  __|______________       _____________|____      |  |        \r
118  | <I>activ.rec</I> f   |       | <I>activ.rec. </I>g   |      |  |\r
119  |               &AElig;&Iacute;&Iacute;&Iacute;&Iacute;&Iacute;&gt;&Iacute;&#181;                |      |  |\r
120  | <I>(1st instance)</I>|       | <I>(1st instance)</I> |      |  |\r
121  |               |       |                |     ____________\r
122  |               |       |<I> ______________</I> ====&gt; | <I>Main</I>     |\r
123  | <I>____________</I>  |       |                |     |          |\r
124  |  ...          |       | <B>call</B> f         |     |f: <B>proc</B>   |\r
125  |  <B>call </B>f       |       |                |     |          |\r
126  |               |       |                |     |g: <B>proc</B>   |\r
127  |               |       |                |     |          |\r
128  -----------------       ------------------     |<I>_________</I> |\r
129    ^                                            |          |\r
130    |       _________________________________&gt;___|<B>call </B>g    |\r
131  ________________       __________________      |          |\r
132 | <I>activ.rec. </I>f   |     | <I>activ.rec. </I>f    &Atilde;&Auml;&Auml;&Auml;&Auml;&gt;&Auml;&#180;          |\r
133 |                &AElig;&Iacute;&lt;&Iacute;&Iacute;&Iacute;&#181;                 |      &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;\r
134 | <I>(2nd instance)</I> |     | <I>(3rd instance)</I>  |\r
135 |                |     |                 |\r
136 | <I>_____________</I>  |     |                 |\r
137 |                |     |                 |\r
138 |  <B>call </B>f        |     |   ...           |\r
139 |                |     |                 |\r
140 |________________|     |_________________|\r
141 </PRE>\r
142 \r
143 <P>\r
144 The instance of main program is the static father of all remaining\r
145 activation records. This may be denoted by single lines (static\r
146 links) leading to the leftmost object. A static father of an object\r
147 is to be searched when the processor finds an identifier e.g.\r
148 a variable which is non-local for a currently executed object.\r
149 This in turn may lead to further searches along the path of static\r
150 links. In every snapshot the set of objects together with the\r
151 set of all static links creates a tree. Every edge of this graph\r
152 corresponds to the tree structure of module nesting in an obvious\r
153 way.\r
154 <P>\r
155 Another kind of arrows (double lines) leads from an object to\r
156 its dynamic father i.e. to the object in which processor subsumes\r
157 the execution of instructions when all the instructions of a current\r
158 object are executed to the <B>end. </B>The<B> </B>graph<B> </B>structure\r
159 of objects and dynamic links differs from the previous one and\r
160 shows &quot;who called who&quot;. Making use of our Pascal experience\r
161 we would like to assert it is a straight line structure. Later\r
162 we shall see that objects and coroutines enrich and complicate\r
163 the picture.\r
164 <P>\r
165 Let us think of a <I>scenario</I> for an activation record of\r
166 a procedure.\r
167 <P>\r
168 <I>About Simula-67 <BR>\r
169 </I>The origins of object oriented programming go back to 1967\r
170 when O.-J.Dahl, K.Nygaard and B.Myhrhaug defined the language\r
171 Simula-67. [books: SIMULA<B>begin</B> by G.Birtwistle, O.J.Dahl,\r
172 Auerbach Publ. and Simula 67 by W.M.Bartol, H.Oktaba, PWN Publ.\r
173 are worth reading].\r
174 <P>\r
175 <I>about class <BR>\r
176 </I>General structure of a class module is as follows:\r
177 <PRE>\r
178 <B>   unit </B>&lt;<I>name_of_class</I> &gt;: <B> class</B> (&lt;<I>formal parameters</I>&gt;);\r
179       &lt;<I>local declarations\r
180         of variables, procedures, functions and classes</I>! &gt;\r
181    <B>begin</B> \r
182       &lt;<I>instructions</I>&gt;\r
183    <B>end</B> &lt;<I>name_of_class</I> &gt;\r
184 </PRE>\r
185 \r
186 <P>\r
187 <U>Example</U> \r
188 <PRE>\r
189 <B>unit </B>circle : <B> class</B> (center: point, radius: real);\r
190 <B>unit</B> intersects: <B>function</B> (c: circle): line;\r
191 {the function returns the line which passes through the intersection points of this circle object and the c circle object, NOTE! it might return <B>none </B>if the two circles have no common points, see how it is solved below }...\r
192 <B>end</B> intersects; \r
193 <B>begin</B> \r
194 <B>if</B> r=0 <B>then</B> <B>raise </B>SignalNoCircle <B>fi\r
195 end</B> circle\r
196 </PRE>\r
197 \r
198 <P>\r
199 Let us remark that the syntactic difference between a procedure\r
200 declaration and class declaration is little: the keyword <U>procedure</U>\r
201 is replaced by another keyword <U>class</U>. However, the semantics\r
202 is entirely different as it will be seen from the diagram-scenario\r
203 below.\r
204 <P>\r
205 <I>declaration of variables of type class <BR>\r
206 </I>One can assume that every declaration of a class introduces\r
207 a new type, for it enables declarations of variables like:\r
208 <PRE>\r
209    <B>var </B>x : circle\r
210 </PRE>\r
211 \r
212 <P>\r
213 objects<BR>\r
214 Objects of classes can be generated by means of expressions (object\r
215 generator) of the form <BR>\r
216 <B>new</B> KLASA(<I>actual_parameters</I>&gt; <BR>\r
217 and stored in variables <BR>\r
218 k:= <B>new</B> KLASA(<I>actual_paramts</I>) <BR>\r
219 One module of a class can serve as a pattern for many objects\r
220 <BR>\r
221 x:= <B>new</B> circle(point1, 88); <BR>\r
222 y:= <B>new</B> circle(<B>new</B> point(45,159), 644) <BR>\r
223 they can have different names. The names help to acces objects\r
224 <BR>\r
225 z:= x <BR>\r
226 and their internal structure <BR>\r
227 x.center ... y.radius <BR>\r
228 The values of the latter expressions will be correspondingly:\r
229 point1 and 644.\r
230 <PRE>\r
231 scenario of an object looks as follows<A NAME="DDE_LINK1"></A><A NAME="DDE_LINK2"></A>\r
232 </PRE>\r
233 \r
234 <P>\r
235 <I>IMPORTANT consequences</I> <BR>\r
236 1. one can use initialization phase to execute an algorithm or\r
237 to initialize objects.<BR>\r
238 <B>EXERCISE</B>. write factorial algorithm using objects and no\r
239 recursion. <BR>\r
240 2. objects can be used as records, <BR>\r
241 <B>EXERCISE</B>. write a piece of program which realizes a tree.\r
242 <BR>\r
243 3. one can send commands to objects, an object is able to execute\r
244 the <B>call</B> commands referring to its local procedure declarations\r
245 (and local functions too) <BR>\r
246 e.g. call x.aProc(a) <BR>\r
247 z:= x.aFun(b) <BR>\r
248 if aProc and aFun were declared in a class C and if x denotes\r
249 an object of the class C.\r
250 <PRE>\r
251 Examples\r
252   complex numbers\r
253 <B>unit</B> complex: <B> class</B> (re,im: real);\r
254 <B>var</B> module: real;\r
255 <B>   unit </B>add:<B> function</B>(z: complex): complex;\r
256 <B>begin</B>      result:= <B> new</B> complex(re+z.re, im+z.im)\r
257 <B>   end</B> add;\r
258 <B>unit </B>mult:<B> function</B>(z: complex): complex;\r
259 <B>begin</B>      result:= <B> new</B> complex(re*z.re-im*z.im, re*z.im+z.re*im)\r
260 <B>   end</B> mult;\r
261 <B>begin</B>   module:= sqrt(re*re+im*im)\r
262 <B>end </B>complex;\r
263 \r
264 Having such class one can create several objects of type complex and manipulate on them e.g.\r
265 <B>program </B>UsingComplex;\r
266 <B>unit</B> complex ...   <B>end</B> complex;\r
267 <B>var</B> c1,c2,z1,z2: complex;\r
268 <B>begin</B>   c1:= <B>new</B> complex(1,9);     <I>{creation of complex number 1+9i}</I>   c2:= <B>new</B> complex(-3,-21); <I> {second object of class complex}</I>   z1:= c1.add(c2.mult(c1));  <I>{now z1=c1+(c2*c1))}</I>   z2:= z1.mult(<B>new </B>complex(z1.re,-z1.im)) <I>{Note an object without a name, once used, it becomes a garbage}</I><B>end </B>UsingComplex\r
269 </PRE>\r
270 \r
271 <P>\r
272 <B>EXERCISE</B>. Write a similar program in Pascal and compare\r
273 : how many parameters transmitted in an expression?, are the concepts\r
274 of complex numbers encapsulated?\r
275 <P>\r
276 EXAMPLE which follows introduces concepts of planar geometry and\r
277 uses them in a prefixed block. The reader can run it and modify\r
278 it as well. {This is the first Loglan program I wrote in December\r
279 1981 to test the compiler.} <BR>\r
280 \r
281 <PRE>\r
282 <B>program</B> CircumscribedCircle;\r
283 \r
284 <B>unit</B> GEOPLAN : <B>class</B>;\r
285 (* This class is in fact a problem oriented language, it offers various facilities for problem solving in the field of analitical planar geometry. \r
286 <I>The class has the following structure:</I> <I>remark the correspondence between software notions of class, procedure, function and</I> <I>the notions of general algebra: algebraic structure, sorts and operations </I> \r
287 \r
288                             GEOPLAN                    &lt;----- class                                       <I>algebraic structure</I>                           /   |   \\r
289                           /    |    \\r
290                          /     |     \\r
291                     POINT    CIRCLE  LINE              &lt;----- classes                                                 <I>sorts</I>                   /  |  \     |     / | \ \r
292                   /   |   \    |    /  |  \          <I>operations</I>                 /    |    |   |   |   |   \           &lt;--|\r
293                 /     |    |   |   |   |    \             |\r
294 opera-     EQUALS   DIST   |   | MEETS |     \            |\r
295                         ERROR  |       |    ERROR         \   tions \r
296                                |       |                  /         \r
297                           INTERSECTS   |                  |\r
298                                        |                  |\r
299                                    PARALLELTO          &lt;--|\r
300 <I>*)</I>   <B>unit</B> POINT : <B>class</B>(X,Y : REAL);\r
301 <B>unit</B> EQUALS : <B>function</B> (Q : POINT) : BOOLEAN;\r
302 <B>begin</B>        RESULT:= Q.X=X <B>and</B> Q.Y=Y ;\r
303 <B>end</B> EQUALS;\r
304 \r
305 <B>unit</B> DIST : <B>function</B> (P : POINT) : REAL;\r
306 <I>(* DISTANCE BETWEEN THIS POINT AND POINT P *)</I>      <B>begin</B>        <B>if</B> P = <B>none</B>        <B>then</B>          <B>call</B> ERROR\r
307 <B>else</B>          <B>result</B>:= SQRT((X-P.X)*(X-P.X)+(Y-P.Y)*(Y-P.Y))\r
308 <B>fi</B>      <B>end</B> DIST;\r
309 \r
310 \r
311 <B>unit</B> <B>virtual</B> ERROR : <B>procedure</B>;\r
312 <B>begin</B>        WRITELN(&quot; THERE IS NO POINT&quot;)\r
313 <B>end</B> ERROR;\r
314 <B>end</B> POINT;\r
315 \r
316 \r
317 <B>unit</B> CIRCLE : <B>class</B> (P : POINT, R : REAL);\r
318 <I>{ THE CIRCLE IS REPRESENTED BY ITS CENTER P AND THE RADIUS R }</I> \r
319 <B>unit</B> INTERSECTS : <B>function</B> (C : CIRCLE) : LINE;\r
320 <I>(* IF BOTH CIRCLES INTERSECT AT 2 POINTS, THE LINE JOINING THEM\r
321   IS RETURNED. IF CIRCLES INTERSECT AT ONE POINT, IT IS TANGENT\r
322   TO BOTH OF THEM. OTHERWISE PERPENDICULAR BISECTION OF THEIR    CENTRES IS RETURNED *)</I>     <B>var</B> R1,R2 : REAL;\r
323 <B>begin</B>       <B>if</B> C=/= <B>none</B>       <B>then</B>         R1:= R*R-P.X*P.X-P.Y*P.Y;\r
324          R2:= C.R*C.R-C.P.X*C.P.X-C.P.Y*C.P.Y;\r
325 <B>result</B> := <B>new</B> LINE (P.X-C.P.X,P.Y-C.P.Y,(R1-R2)/2);\r
326 <B>fi</B>     <B>end</B> INTERSECTS;\r
327 \r
328 <B>begin</B>     <B>if</B> P=<B>none</B> \r
329 <B>then</B>       WRITELN (&quot; WRONG CENTRE&quot;)\r
330 <B>fi</B>   <B>end</B> CIRCLE;\r
331 \r
332 \r
333 <B>unit</B> LINE : <B>class</B> (A,B,C : REAL);\r
334 <I>{LINE IS REPRESENTED BY COEFFICIENTS OF EQUATION AX+BY+C=0 }</I> \r
335 \r
336 <B>unit</B> MEETS : <B>function</B> (L : LINE) : POINT;\r
337 <I>     (* IF TWO LINES INTERSECT function MEETS RETURNS THE POINT\r
338           OF INTERSECTION, OTHERWISE RETURNS NONE *)</I>     <B>VAR</B> T  : REAL;\r
339 <B>begin</B>       <B>if</B> L =/= <B>none</B> <B>and</B> <B>not</B> PARALLELTO (L)\r
340 <B>then</B>         T := 1/(L.A*B-L.B*A);\r
341 <B>result</B> := <B>new</B> POINT (-T*(B*L.C-C*L.B),\r
342                                T*(A*L.C-C*L.A));\r
343 <B>else</B>         <B>call</B> ERROR\r
344 <B>fi</B>     <B>end</B> MEETS;\r
345 <B>unit</B> PARALLELTO : <B>function</B> (L : LINE) : BOOLEAN;\r
346 <B>begin</B>       <B>if</B> L=/= <B>none</B>       <B>then</B>         <B>if</B> A*L.B-B*L.A = 0.0\r
347 <B>then</B>           <B>result</B>:=TRUE; WRITELN(&quot; zle&quot;); \r
348 <B>else</B>           <B>result</B>:=FALSE; WRITELN(&quot; dobrze&quot;);\r
349 <B>fi</B>        \r
350 <B>else</B>         <B>call</B> ERROR\r
351 <B>fi</B>     <B>end</B> PARALLELTO;\r
352 \r
353 <B>unit</B> <B>virtual</B> ERROR  : <B>procedure</B>;\r
354 <B>begin</B>       WRITELN(&quot; THERE IS NO LINE&quot;)\r
355 <B>end</B> ERROR;\r
356 \r
357 <B>var</B> D : REAL;\r
358 \r
359 <B>begin</B> <I>(* NORMALIZATION OF COEFFICIENTS *)</I>     D := SQRT(A*A+B*B);\r
360 <B>if</B> D= 0.0\r
361 <B>then</B>       WRITELN( &quot; ZLE, ZERO&quot;); <B>call</B> ERROR\r
362 <B>else</B>       A := A/D;\r
363        B := B/D;\r
364        C := C/D;\r
365 <B>fi</B>   <B>end</B> LINE;\r
366 \r
367 <B>end</B> GEOPLAN;\r
368 \r
369 \r
370 \r
371 <B>begin</B> \r
372 <B>pref</B> GEOPLAN <B>block</B><I>    (* THE LANGUAGE GEOPLAN IS USED FOR FINDING THE CIRCLE CIRCUMSCRIBED ON A GIVEN TRIANGLE:</I>             \r
373                           P\r
374                          / \\r
375                         /   \\r
376                        /  .&lt;-\------- CENTRE  \r
377                       /       \\r
378                      Q---------R \r
379 <I>*)</I>  <B>taken</B> POINT,LINE,CIRCLE;\r
380 \r
381 <B>var</B> P,Q,R,CENTRE : POINT,\r
382     L1,L2 : LINE,\r
383     C1,C2,C4 : CIRCLE,\r
384     RADIUS, X1,Y1 : REAL;\r
385 \r
386 <B>begin</B>   <B>do</B>    WRITELN(&quot;THIS PROGRAM FINDS THE CENTRE AND RADIUS OF &quot;);\r
387     WRITELN(&quot; THE CIRCLE CIRCUMSCRIBED  ON A GIVEN TRIANGLE &quot;);\r
388     WRITELN(&quot; GIVE THE VERTICES COEFFICIENTS OF A TRIANGLE&quot;);\r
389     WRITELN(&quot; X1,Y1= ?? ??&quot;);\r
390     READ (X1,Y1);\r
391     P := <B>new</B> POINT(X1,Y1);\r
392     WRITELN(&quot; &quot;,X1,&quot;   &quot;,Y1);\r
393     WRITELN(&quot; X2,Y2= ?? ??&quot;);\r
394     READ (X1,Y1);\r
395     Q := <B>new</B> POINT(X1,Y1);\r
396     WRITELN(&quot; &quot;,X1,&quot;   &quot;,Y1);\r
397     WRITELN(&quot; X3,Y3= ?? ??&quot;);\r
398     READ (X1,Y1);\r
399     R := <B>new</B> POINT (X1,Y1);\r
400     WRITELN(&quot; &quot;,X1,&quot;   &quot;,Y1);\r
401 \r
402     RADIUS := P.DIST(Q) + Q.DIST(R);\r
403     C1 := <B>new</B> CIRCLE (P,RADIUS);\r
404     C2 := <B>new</B> CIRCLE (Q,RADIUS);\r
405     C4 := <B>new</B> CIRCLE (R,RADIUS);\r
406 \r
407     L1 := C2.INTERSECTS(C1); \r
408 <I>             (*THE PERPENDICULAR BISECTOR OF THE SIDE PQ*)</I>    L2 := C2.INTERSECTS(C4); \r
409 <I>             (*THE PERPENDICULAR BISECTOR OF THE SIDE QR *)</I> \r
410     CENTRE := L1.MEETS(L2);\r
411 \r
412 <B>if</B> CENTRE = <B>none</B>    <B>then</B>      WRITELN(&quot; ALL POINTS LAY ON THE SAME LINE&quot;);\r
413 <B>else</B>      WRITELN(&quot; THE CIRCUMSCRIBED CIRCLE IS AS FOLOWS:&quot;);\r
414       WRITELN(&quot; CENTRE = (&quot;,CENTRE.X,',',CENTRE.Y,')');\r
415       WRITELN(&quot; RADIUS = &quot;,CENTRE.DIST(P));\r
416 <B>fi</B>   <B>od</B>  <B>end\r
417 end</B> \r
418 The static structure of modules in the above program is the tree\r
419 \r
420 \r
421                           PROGRAM\r
422                           /    \\r
423                          /      \\r
424                         /        \     \r
425                        /          \\r
426                    GEOPLAN      <B>pref</B> GEOPLAN <B>block</B>            \r
427 \r
428                   /   |   \\r
429                  /    |    \\r
430                 /     |     \\r
431            POINT    CIRCLE  LINE             \r
432 \r
433           /  |  \     |     / | \ \r
434          /   |   \    |    /  |  \\r
435         /    |    |   |   |   |   \          \r
436        /     |    |   |   |   |    \         \r
437   EQUALS   DIST   |   | MEETS |     \        \r
438                ERROR  |       |    ERROR     \r
439                       |       |\r
440                       |       |              \r
441                  INTERSECTS   |              \r
442                               |              \r
443                           PARALLELTO         \r
444 \r
445 \r
446 The edges lead from a module to its static father (up). The module GEOPLAN and the block prefixed with the name GEOPLAN are in another relation: namely of prefixing, or inheritance. We shall develop this remark later. What is worth noting here is that the structure of GEOPLAN remains intact. This is due to the fact that the class GEOPLAN encapsulates the structure of internal classes and modules.\r
447 </PRE>\r
448 \r
449 <P>\r
450 Let us view a few snapshots.\r
451 <PRE>\r
452    &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191;      The initial snapshot shows just one \r
453    |<B>program</B>          |      dynamic instance of the main prog-\r
454    | &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191; |      ram.\r
455    | |GEOPLAN      | |\r
456    | |             | |      The only instruction to be execu-\r
457    | |             | |      ted is the instruction of prefixed \r
458    | |             | |      block.\r
459    | |             | |\r
460    | &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave; |\r
461    |                 |\r
462    | &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191; |\r
463    | |<B>block</B>        | |    ---- block prefixed with GEOPLAN\r
464    | |             | |\r
465    | |             | |\r
466    | |             | |\r
467    | |             | |\r
468    | |             | |\r
469    | &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave; |\r
470    |                 |\r
471    &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;\r
472 \r
473 Just before the first writeln ... instruction\r
474 \r
475    &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191;SL          &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191;\r
476    |program          &Atilde;&Auml;&Auml;&lt;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#180;GEOPLAN <B>block</B>    |\r
477    | &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191; |DL          |                 |\r
478    | |GEOPLAN      | &AElig;&Iacute;&Iacute;&lt;&Iacute;&Iacute;&Iacute;&Iacute;&Iacute;&Iacute;&Iacute;&Iacute;&Iacute;&#181; all features of |\r
479    | |             | |            | GEOPLAN inhtd.  |\r
480    | |             | |            |                 |\r
481    | |             | |            | P  point <B>none</B>   |\r
482    | |             | |            | Q  point <B>none</B>   |\r
483    | &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave; |            | R  point <B>none</B>   |\r
484    |                 |            | C1 circle <B>none</B>  |\r
485    | &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191; |            | C2 circle <B>none</B>  |\r
486    | |<B>block</B>        | |            | C4 circle <B>none</B>  |\r
487    | |             | |            | L1 line <B>none</B>    |\r
488    | |             | |            | L2 line <B> none</B>   |\r
489    | |             | |            | RADIUS real 0   |\r
490    | |             | |            | CENTRE          |\r
491    | |             | |            |                 |\r
492    | &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave; |            |                 |\r
493    |                 |            |                 |\r
494    &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;            &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;\r
495     This may be a snapshot just before the instruction putting radius to be equal the sum of distances PQ and QR. We omitted all SL links and DL links in order to simplify the picture. \r
496 \r
497 \r
498    &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191;   &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191;       &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191;\r
499    |program          |   |GEOPLAN <B>block</B>    | &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&#180; X real 4 |\r
500    | &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191; |   |                 | |     | Y real 6 |\r
501    | |GEOPLAN      | |   | all features of | |     &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;\r
502    | |             | |   | GEOPLAN inhtd.  | |     &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191;\r
503    | |             | |   |                 | | &Uacute;&Auml;&Auml;&Auml;&#180; X real -4|\r
504    | |             | |   | P  point &Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Aring;&Auml;&Ugrave; |   | Y real 88|\r
505    | |             | |   | Q  point &Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Aring;&Auml;&Auml;&Auml;&Ugrave;   &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;\r
506    | &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave; |   | R  point &Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Aring;&Auml;&Auml;&Auml;&#191;   &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191;\r
507    |                 |   | C1 circle <B>none</B>  |   |   | X real -9|\r
508    | &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191; |   | C2 circle <B>none</B>  |   &Agrave;&Auml;&Auml;&Auml;&#180; Y real 23|\r
509    | |<B>block</B>        | |   | C4 circle <B>none</B>  |       &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;\r
510    | |             | |   | L1 line <B>none</B>    |                   \r
511    | |             | |   | L2 line <B> none</B>   |                \r
512    | |             | |   | RADIUS real 0   |\r
513    | |             | |   |                 |\r
514    | |             | |   |                 |\r
515    | &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave; |   | =&gt; radius:= ... |\r
516    |                 |   |                 |\r
517    &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;   &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;\r
518 \r
519 \r
520 \r
521 \r
522    This may be a snapshot just after the three circles were created.  \r
523 \r
524 \r
525    ___________________   ___________________       &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191;\r
526    |program          |   |GEOPLAN <B>block</B>    | &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&#180; X real 4 |\r
527    | _______________ |   |                 | |     | Y real 6 |\r
528    | |GEOPLAN      | |   | all features of | |     &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;\r
529    | |             | |   | GEOPLAN inhtd.  | |     &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191;\r
530    | |             | |   |                 | | &Uacute;&Auml;&Auml;&Auml;&#180; X real -4|\r
531    | |             | |   | P  point &Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Aring;&Auml;&Ugrave; |   | Y real 88|\r
532    | |             | |   | Q  point &Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Aring;&Auml;&Auml;&Auml;&Ugrave;   &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;\r
533    | |_____________| |   | R  point &Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Aring;&Auml;&Auml;&Auml;&#191;   &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191;\r
534    |                 |   | C1 circle &Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Aring;&Auml;&Auml;&#191;|   | X real -9|\r
535    | _______________ |   | C2 circle &Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Aring;&Auml;&#191;|&Agrave;&Auml;&Auml;&Auml;&#180; Y real 23|\r
536    | |<B>block</B>        | |   | C4 circle &Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Aring;&#191;|&Agrave;&Auml;&Auml;&#191; &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;\r
537    | |             | |   | L1 line <B>none</B>    ||&Agrave;&Auml;&Auml;&#191;| &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191;\r
538    | |             | |   | L2 line <B> none</B>   |&Agrave;&Auml;&#191; |&Agrave;&Auml;&#180;CENTER  P |\r
539    | |             | |   | RADIUS real 0   |  | |  &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;\r
540    | |             | |   |                 |  | &Agrave;&Auml;&Auml;&Acirc;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191;\r
541    | |             | |   |                 |  |    |CENTER  Q |\r
542    | |_____________| |   | =&gt; L1:= ...     |  |    &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;\r
543    |                 |   |                 |  |    &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191;\r
544    |_________________|   |_________________|  &Agrave;&Auml;&Auml;&Auml;&Auml;&#180;CENTER  R |\r
545                                                    &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;\r
546 </PRE>\r
547 \r
548 <P>\r
549 <TT>This may be a snapshot of situation in which two lines were\r
550 created and their intersection point was found.</TT> \r
551 <PRE>\r
552    &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191;   &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191;       &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191;\r
553    |program          |   |GEOPLAN <B>block</B>    | &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&#180; X real 4 |\r
554    | &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191; |   |                 | |     | Y real 6 |\r
555    | |GEOPLAN      | |   | all features of | |     &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;\r
556    | |             | |   | GEOPLAN inhtd.  | |     &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191;\r
557    | |             | |   |                 | | &Uacute;&Auml;&Auml;&Auml;&#180; X real -4|\r
558    | |             | |   | P  point  &Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Aring;&Auml;&Ugrave; |   | Y real 88|\r
559    | |             | |   | Q  point  &Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Aring;&Auml;&Auml;&Auml;&Ugrave;   &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;\r
560    | &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave; |   | R  point  &Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Aring;&Auml;&Auml;&Auml;&#191;   &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191;\r
561    |                 |   | C1 circle &Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Aring;&Auml;&Auml;&#191;|   | X real -9|\r
562    | &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191; |   | C2 circle &Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Aring;&Auml;&#191;|&Agrave;&Auml;&Auml;&Auml;&#180; Y real 23|\r
563    | |<B>block</B>        | |   | C4 circle &Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Aring;&#191;|&Agrave;&Auml;&Auml;&#191; &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;\r
564    | |             | |   | L1 line  &Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191;||&Agrave;&Auml;&Auml;&#191;| &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191;\r
565    | |             | |   | L2 line <B> </B>&Auml;&Auml;&Auml;&Auml;&Auml;&#191;||&Agrave;&Auml;&#191; |&Agrave;&Auml;&#180;CENTER  P |\r
566    | |             | |   | RADIUS real 0 |&Agrave;&Aring;&Auml;&#191;| |  &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;\r
567    | |             | |   | CENTRE &Auml;&#191;     | | || &Agrave;&Auml;&Auml;&Acirc;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191;\r
568    | |             | |   |         |     | | ||    |CENTER  Q |\r
569    | &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave; |   | =&gt; <B>if </B>CE|NTRE | | ||    &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;\r
570    |                 |   |         |     | | ||    &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191;\r
571    &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;   &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Aring;&Auml;&Auml;&Auml;&Auml;&Auml;&Aring;&Auml;&Ugrave; |&Agrave;&Auml;&Auml;&Auml;&Auml;&#180;CENTER  R |\r
572             &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;     |   |     &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;\r
573    &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Aacute;&Auml;&Auml;&Auml;&Auml;&#191;      &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#180;   | &Uacute;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&#191;\r
574    | X <I><B>coeff. of</B> </I>|      |A real ...      |   &Agrave;&Auml;&#180;A real   ...  |\r
575    | Y <I><B>solution</B> </I> |      |B real ...      |     |B real   ...  |\r
576    |             |      |C real ...      |     |C real   ...  |\r
577    &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;      &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;     &Agrave;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Auml;&Ugrave;\r
578 \r
579 \r
580 <B>Exercises</B>. Add drawing functions as attributes of classes point, line, circle.   \r
581 Write the algorithm inverting a point w.r.t. a given circle.\r
582 </PRE>\r
583 \r
584 <ADDRESS>\r
585 Andrzej Salwicki \r
586 </ADDRESS>\r
587 \r
588 </BODY>\r
589 \r
590 </HTML>\r