module DATA is !library !update "2021-b" ------------------------------------------------------------------------------ type ADR is range 1...3 of NAT end type ------------------------------------------------------------------------------ type MSG is range 1...3 of NAT with ==, >, >= end type ------------------------------------------------------------------------------ function N: MSG is return 3 of MSG end function ------------------------------------------------------------------------------ function <+> (X, Y: MSG): MSG is var RESULT: NAT in RESULT := NAT (X) + NAT (Y); assert RESULT <= 2 * NAT (N); if RESULT > NAT (N) then RESULT -= NAT (N) end if; return MSG (RESULT) end var end function ------------------------------------------------------------------------------ function <-> (X, Y: MSG): MSG is var RESULT: NAT in RESULT := NAT (X); if RESULT <= NAT (Y) then RESULT += NAT (N) end if; return MSG (RESULT - NAT (Y)) end var end function ------------------------------------------------------------------------------ type TYPEMSG is FIRST, SECOND end type ------------------------------------------------------------------------------- end module