mirror of
https://github.com/vishapoberon/oberonbyexample.git
synced 2026-04-05 21:02:25 +00:00
tmp
This commit is contained in:
commit
447b87d2ed
3 changed files with 96 additions and 0 deletions
68
Days.Mod
Normal file
68
Days.Mod
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
MODULE Days;
|
||||||
|
|
||||||
|
TYPE
|
||||||
|
Day* = POINTER TO DayDesc;
|
||||||
|
DayDesc = RECORD
|
||||||
|
next, prev : Day
|
||||||
|
END;
|
||||||
|
Week = ARRAY 7 OF Day;
|
||||||
|
|
||||||
|
VAR
|
||||||
|
sun*, mon*, tue*, wed*, thu*, fri*, sat* : Day;
|
||||||
|
week: Week;
|
||||||
|
|
||||||
|
PROCEDURE Next*(d : Day): Day;
|
||||||
|
BEGIN
|
||||||
|
RETURN d.next
|
||||||
|
END Next;
|
||||||
|
|
||||||
|
PROCEDURE Prev*(d: Day): Day;
|
||||||
|
BEGIN
|
||||||
|
RETURN d.prev;
|
||||||
|
END Prev;
|
||||||
|
|
||||||
|
PROCEDURE inc(VAR j: SHORTINT);
|
||||||
|
BEGIN
|
||||||
|
IF j = 6 THEN
|
||||||
|
j := 0
|
||||||
|
ELSE
|
||||||
|
INC(j)
|
||||||
|
END
|
||||||
|
END inc;
|
||||||
|
|
||||||
|
PROCEDURE dec(VAR j: SHORTINT);
|
||||||
|
BEGIN
|
||||||
|
IF j = 0 THEN
|
||||||
|
j := 6
|
||||||
|
ELSE
|
||||||
|
DEC(j)
|
||||||
|
END
|
||||||
|
END dec;
|
||||||
|
|
||||||
|
PROCEDURE init(VAR w : Week);
|
||||||
|
VAR
|
||||||
|
i,j : SHORTINT;
|
||||||
|
BEGIN
|
||||||
|
i := 0;
|
||||||
|
REPEAT
|
||||||
|
j := i; inc(j);
|
||||||
|
w[i].next := w[j];
|
||||||
|
j := i; dec(j);
|
||||||
|
w[i].prev := w[j];
|
||||||
|
INC(i)
|
||||||
|
UNTIL i > 6;
|
||||||
|
END init;
|
||||||
|
|
||||||
|
BEGIN
|
||||||
|
NEW(sun); NEW(mon); NEW(tue); NEW(wed); NEW(thu); NEW(fri); NEW(sat);
|
||||||
|
week[0] := sun;
|
||||||
|
week[1] := mon;
|
||||||
|
week[2] := tue;
|
||||||
|
week[3] := wed;
|
||||||
|
week[4] := thu;
|
||||||
|
week[5] := fri;
|
||||||
|
week[6] := sat;
|
||||||
|
|
||||||
|
init(week);
|
||||||
|
|
||||||
|
END Days.
|
||||||
6
readme.md
Normal file
6
readme.md
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
|
||||||
|
Example aimed to show how to survive without enumerations in Oberon.
|
||||||
|
|
||||||
|
This way is even cooler than enumerations. (:
|
||||||
|
|
||||||
22
test.Mod
Normal file
22
test.Mod
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
MODULE test;
|
||||||
|
|
||||||
|
IMPORT Days, Out;
|
||||||
|
|
||||||
|
VAR today, yesterday, tomorrow: Days.Day;
|
||||||
|
|
||||||
|
BEGIN
|
||||||
|
today := Days.mon; (*init*)
|
||||||
|
|
||||||
|
yesterday := Days.Prev(today);
|
||||||
|
IF yesterday = Days.sun
|
||||||
|
THEN
|
||||||
|
Out.String("it works!"); Out.Ln
|
||||||
|
END;
|
||||||
|
tomorrow := Days.Next(today);
|
||||||
|
|
||||||
|
IF tomorrow = Days.tue
|
||||||
|
THEN
|
||||||
|
Out.String("it works!"); Out.Ln
|
||||||
|
END;
|
||||||
|
|
||||||
|
END test.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue