[Oberon] Modula2 vs Oberon IMPORT
Chris Burrows
chris at cfbsoftware.com
Sun Jan 9 00:05:32 CET 2011
> -----Original Message-----
> From: Jan Verhoeven [mailto:jan at verhoeven272.nl]
> Sent: Sunday, 9 January 2011 3:17 AM
> To: ETH Oberon and related systems
> Subject: Re: [Oberon] Modula2 vs Oberon IMPORT
>
>
> Yes but it will not add clarity to your sources. Unless you
> use a silly
> kind of importing:
>
> PROCEDURE ReadString (string : ARRAY OF CHAR);
>
> IMPORT In.ReadString;
>
> BEGIN
> In.ReadString (string)
> END ReadString;
>
> I'm not sure if the IMPORT in this example will be accepted by all
> compilers.
>
I don't know any Oberon compiler that would accept the above, but every
Oberon compiler should compile the following (assuming In is an available
import):
MODULE M;
IMPORT In;
PROCEDURE ReadString(VAR string: ARRAY OF CHAR);
BEGIN
In.ReadString(string)
END ReadString;
END M.
I have seen this technique used in ETH code and it can help to remove
clutter e.g.
CASE reg OF
FP : WrStr("FP")
| SP : WrStr("SP")
| LR : WrStr("LR")
| PC : WrStr("PC")
| CPSR : WrStr("CPSR")
| SPSR : WrStr("SPSR")
ELSE
WrChar('R'); WrInt(reg)
END
instead of:
CASE reg OF
FP : Texts.WriteString(w, "FP")
| SP : Texts.WriteString(w, "SP")
| LR : Texts.WriteString(w, "LR")
| PC : Texts.WriteString(w, "PC")
| CPSR : Texts.WriteString(w, "CPSR")
| SPSR : Texts.WriteString(w, "SPSR")
ELSE
Texts.WriteChar(w, 'R'); Texts.WriteInt(w, reg)
END
Chris.
More information about the Oberon
mailing list