Added upstream from http://ftp.icm.edu.pl/pub/loglan/
[loglan.git] / HTML / MicroMan / Classes.htm
1 <!doctype html public "-//IETF//DTD HTML//EN">\r
2 <HTML>\r
3 \r
4 <HEAD>\r
5 \r
6 <TITLE>Classes</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 <P>\r
15 <U><I>Loglan 82, A micro-manual of the programming language -\r
16 Basic constructs and facilities</I></U>\r
17 <H1><IMG ALIGN=MIDDLE SRC="gifs/logo2.gif"> 5) Classes</H1>\r
18 <HR>\r
19 \r
20 <P>\r
21 Class is a facility which covers such programming constructs as\r
22 structured type, package, access type, data structure etc. To\r
23 begin with the presentation of this construct, let us consider\r
24 a structured type assembled from primitive ones:\r
25 <P>\r
26 <IMG SRC="gifs/cl01.gif"> \r
27 <P>\r
28 The above class declaration has the attributes : dollars (real),\r
29 not_paid (boolean), and year,month,day (integer). Wherever class\r
30 bill is visibile one can declare variables of type bill:\r
31 <PRE>\r
32 <B>var</B> x,y,z: bill\r
33 </PRE>\r
34 \r
35 <P>\r
36 The values of variables x, y, z can be the addresses of objects\r
37 of class bill. These variables are called reference variables.\r
38 With reference variable one can create and operate the objects\r
39 of reference variable type.\r
40 <P>\r
41 An object of a class is created by the class generation statement\r
42 (new), and thereafter, its attributes are accessed through dot\r
43 notation.\r
44 <P>\r
45 <IMG SRC="gifs/cl03.gif"> \r
46 <P>\r
47 If an object of class bill has been created (new bill) and its\r
48 address has been assigned to variable x (x:=new bill), then the\r
49 attributes of that object are accessible through dot notation\r
50 (remote access). The expression x.dollars gives , for instance,\r
51 the remote access to attribute dollars of the object referenced\r
52 by x. All attributes of class objects are initialized as usual.\r
53 For the above example the object referenced by x, after the execution\r
54 of the specified sequence of statements, has the following structure:\r
55 <P>\r
56 <IMG SRC="gifs/Fig0401.gif"> \r
57 <P>\r
58 The object referenced by y and z has the following structure:\r
59 <P>\r
60 <IMG SRC="gifs/Fig0402.gif"> \r
61 <P>\r
62 The value none is the default initial value of any reference variable\r
63 and denotes no object. A remote access to an attribute of none\r
64 raises a run time error.\r
65 <P>\r
66 Class may have also formal parameters (as procedures and functions).\r
67 Kinds and transmission modes of formal parameters are the same\r
68 as in the case of procedures.\r
69 <P>\r
70 Example:\r
71 <P>\r
72 <IMG SRC="gifs/cl04.gif"> \r
73 <P>\r
74 Let, for instance, variables z1, z2, z3 be of type node. Then\r
75 the sequence of statements:\r
76 <P>\r
77 <IMG SRC="gifs/cl05.gif"> \r
78 <P>\r
79 creates the structure:\r
80 <P>\r
81 <IMG SRC="gifs/Fig0403.gif"> \r
82 <P>\r
83 where arrows denote the values of the reference variables.\r
84 <P>\r
85 Class may also have a sequence of statements (as any other unit).\r
86 That sequence can initialize the attributes of the class objects.\r
87 <P>\r
88 Example:\r
89 <P>\r
90 <IMG SRC="gifs/cl06.gif"> \r
91 <P>\r
92 Attribute module is evaluated for any object generation of class\r
93 complex:\r
94 <P>\r
95 <IMG SRC="gifs/cl07.gif"> \r
96 <P>\r
97 For the execution of a class generator, first a class object is\r
98 created, then the input parameters are transmitted , and finally,\r
99 the sequence of statements (if any) is performed. Return is made\r
100 with the execution of return statement or the final end of a unit.\r
101 Upon return the output parameters are transmitted.\r
102 <P>\r
103 Procedure object is automatically deallocated when return is made\r
104 to the caller. Class object is not deallocated , its address can\r
105 be assigned to a reference variable, and its attributes can be\r
106 thereafter accessed via this variable.\r
107 <P>\r
108 The classes presented so far had only variable attributes. In\r
109 general, class attributes may be also other syntactic entities,\r
110 such as constants, procedures, functions, classes etc. Classes\r
111 with procedure and function attributes provide a good facility\r
112 to define data structures.\r
113 <P>\r
114 Example:\r
115 <P>\r
116 A push_down memory of integers may be implemented in the following\r
117 way:\r
118 <P>\r
119 <IMG SRC="gifs/cl08.gif"> \r
120 <P>\r
121 Assume that somewhere in a program reference variables of type\r
122 push_down are declared (of course, in place where push_down is\r
123 visibile):\r
124 <P>\r
125 <IMG SRC="gifs/cl09.gif"> \r
126 <P>\r
127 Three different push_down memories may be now generated:\r
128 <P>\r
129 <IMG SRC="gifs/cl10.gif"> \r
130 <P>\r
131 One can use these push_down memories as follows:\r
132 <P>\r
133 <IMG SRC="gifs/cl11.gif"> \r
134 <P>\r
135 etc. <HR>\r
136 \r
137 <P>\r
138 <A HREF="Procedur.htm"><IMG SRC="gifs/PrevPage.gif"></A>\r
139  <A HREF="HomePage.htm"> <IMG SRC="gifs/HomePage.gif"></A> \r
140 <A HREF="adjustab.htm"><IMG SRC="gifs/NextPage.gif"></A>\r
141 <HR>\r
142 \r
143 <ADDRESS>\r
144 Last update 02/07/95 \r
145 </ADDRESS>\r
146 \r
147 <ADDRESS>\r
148 Comments, suggestions and critiques are welcome to : <A HREF="mailto:linfo062@crisv2.univ-pau.fr">linfo062@crisv2.univ-pau.fr</A>\r
149 \r
150 </ADDRESS>\r
151 \r
152 </BODY>\r
153 \r
154 </HTML>\r