[Oberon] System V5 - Definitions and Implementations
thomas.kral at email.cz
thomas.kral at email.cz
Sat Apr 9 17:51:06 CEST 2016
Hi,
I found this example in Programming in Oberon (PIO) book. The PO 2013 project documentation uses Definitions frequently to describe various system functionality, it is easy for the reader to follow concepts without need to understand all details of Implementation.
It is a very descriptive aid for documenting, however how can Definitions be used from a programmer's point of view?
DEFINITION Buffer;
VAR nonempty, nonfull: BOOLEAN;
PROCEDURE put(x: INTEGER);
PROCEDURE get(VAR x: INTEGER);
END Buffer.
MODULE Buffer; (*cyclic buffer of integers*)
CONST N = 100;
VAR nonempty*, nonfull*: BOOLEAN;
in, out, n: INTEGER;
buf: ARRAY N OF INTEGER;
PROCEDURE put*(x: INTEGER);
BEGIN
IF n < N THEN
buf[in] := x; in := (in+1) MOD N;
INC(n); nonfull := n < N; nonempty := TRUE
END
END put;
PROCEDURE get*(VAR x: INTEGER);
BEGIN
IF n > 0 THEN
x := buf[out]; out := (out+1) MOD N;
DEC(n); nonempty := n > 0; nonfull := TRUE
END
END get;
BEGIN (*initialize*) n := 0; in := 0; out := 0;
nonempty := FALSE; nonfull := TRUE
END Buffer.
Many thanks Tomas
More information about the Oberon
mailing list