home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Unsorted BBS Collection
/
thegreatunsorted.tar
/
thegreatunsorted
/
programming
/
misc_programming
/
oberon.asc
< prev
next >
Wrap
Text File
|
1995-02-02
|
2KB
|
121 lines
_THE OBERON PROGRAMMING LANGUAGE_
by Josef Templ
Example 1:
MODULE M;
IMPORT M1, M2 := MyModule;
TYPE
T* = RECORD
f1*: INTEGER;
f2: ARRAY 32 OF CHAR
END ;
PROCEDURE P*(VAR p: T);
BEGIN
M1.P(p.f1, p.f2)
END P;
END M.
Example 2:
WITH v: T1 DO
v treated as beeing declared with static
type T1 in this statement sequence
END
Example 3:
TYPE
Object = POINTER TO ObjDesc;
ObjDesc = RECORD ... END ;
ObjMsg = RECORD END ;
CopyMsg = RECORD(ObjMsg)
deep: BOOLEAN; cpy: Object
END ;
ConsumeMsg = RECORD(ObjMsg)
obj: Object; x, y: INTEGER
END ;
Example 4:
PROCEDURE Handle (O: Object; VAR M: ObjMsg);
BEGIN
IF M IS CopyMsg THEN handle copy message
ELSIF M IS ... handle further message types
ELSE ignore
END
END Handle;
Example 5:
(a)
TYPE Object = POINTER TO ObjDesc;
ObjMsg = RECORD END ;
Handler = PROCEDURE (O: Object; VAR M: ObjMsg);
ObjDesc = RECORD
handle: Handler
END ;
(b)
TYPE
MyObject = POINTER TO MyObjDesc;
MyObjDesc = RECORD (Object)
extended fields
END ;
(c)
VAR o: MyObject;
NEW(o); o.handle := MyHandle;
(d)
VAR m: CopyMsg;
m.deep := TRUE; m.obj := NIL;
o.handle(o, m);
Example 6:
PROCEDURE MyHandle (O: Object; VAR M: ObjMsg);
BEGIN
WITH O: MyObject DO
IF M IS CopyMsg THEN handle copy message
ELSIF M IS ... handle further message types
ELSE Objects.Handle(O, M)
END
END
END MyHandle;
Example 7:
PROCEDURE Broadcast(VAR M: ObjMsg);
VAR o: Object;
BEGIN o := firstObj;
WHILE o _ NIL DO o.handle(o, M); o := nextObj END
END Broadcast;