home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / programming / misc_programming / oberon.asc < prev    next >
Text File  |  1995-02-02  |  2KB  |  121 lines

  1. _THE OBERON PROGRAMMING LANGUAGE_
  2. by Josef Templ
  3.   
  4.  
  5. Example 1:
  6.  
  7. MODULE M;
  8. IMPORT M1, M2 := MyModule;
  9.  
  10. TYPE
  11.   T* = RECORD
  12.     f1*: INTEGER;
  13.     f2: ARRAY 32 OF CHAR
  14.   END ;
  15.  
  16. PROCEDURE P*(VAR p: T);
  17. BEGIN
  18.   M1.P(p.f1, p.f2)
  19. END P;
  20.  
  21. END M.
  22.  
  23.  
  24. Example 2: 
  25.  
  26.   WITH v: T1 DO
  27.     v treated as beeing declared with static
  28.     type T1 in this statement sequence
  29.   END
  30.  
  31.  
  32.  
  33. Example 3: 
  34.  
  35. TYPE
  36.   Object = POINTER TO ObjDesc;
  37.   ObjDesc = RECORD ... END ;
  38.  
  39.   ObjMsg = RECORD END ;
  40.  
  41.   CopyMsg = RECORD(ObjMsg)
  42.     deep: BOOLEAN; cpy: Object
  43.   END ;
  44.  
  45.   ConsumeMsg = RECORD(ObjMsg)
  46.     obj: Object; x, y: INTEGER
  47.   END ;
  48.  
  49.  
  50. Example 4: 
  51.  
  52. PROCEDURE Handle (O: Object; VAR M: ObjMsg);
  53. BEGIN
  54.   IF M IS CopyMsg THEN handle copy message
  55.   ELSIF M IS ... handle further message types
  56.   ELSE ignore
  57.   END
  58. END Handle;
  59.  
  60.  
  61. Example 5: 
  62.  
  63.  
  64. (a)
  65.  
  66. TYPE   Object = POINTER TO ObjDesc;
  67.   ObjMsg = RECORD END ;
  68.   Handler = PROCEDURE (O: Object; VAR M: ObjMsg);
  69.   ObjDesc = RECORD
  70.     handle: Handler
  71.   END ;
  72.  
  73.  
  74. (b)
  75.  
  76.  
  77. TYPE
  78.   MyObject = POINTER TO MyObjDesc;
  79.   MyObjDesc = RECORD (Object)
  80.     extended fields
  81.   END ;
  82.  
  83.  
  84.  
  85. (c)
  86.  
  87. VAR o: MyObject;
  88. NEW(o); o.handle := MyHandle;
  89.  
  90.  
  91. (d)
  92.  
  93. VAR m: CopyMsg;
  94. m.deep := TRUE; m.obj := NIL;
  95. o.handle(o, m);
  96.  
  97.  
  98. Example 6:
  99.  
  100. PROCEDURE MyHandle (O: Object; VAR M: ObjMsg);
  101. BEGIN
  102.   WITH O: MyObject DO
  103.     IF M IS CopyMsg THEN handle copy message
  104.     ELSIF M IS ... handle further message types
  105.     ELSE Objects.Handle(O, M)
  106.     END
  107.   END
  108. END MyHandle;
  109.  
  110.  
  111. Example 7:
  112.  
  113. PROCEDURE Broadcast(VAR M: ObjMsg);
  114.   VAR o: Object;
  115. BEGIN o := firstObj;
  116.   WHILE o _ NIL DO o.handle(o, M); o := nextObj END
  117. END Broadcast;
  118.  
  119.  
  120.  
  121.