[Oberon] Oxford Oberon-2 Compiler and local procedures

Martin Bishop martinbishop at bellsouth.net
Thu Nov 27 05:20:28 MET 2008


I translated some Pascal code for "deep binding" (aka closures) into Oberon.

MODULE Closure;

   IMPORT Out;

   TYPE Function = PROCEDURE ();

   PROCEDURE A(I: INTEGER; P: Function);

      PROCEDURE B;
      BEGIN
         Out.Int(I,0);
      END B;

   BEGIN
      IF I > 1 THEN
         P
      ELSE
         A(2, B);
      END;
   END A;

   PROCEDURE C;
   BEGIN
   END C;

BEGIN
   A(1, C);
   Out.Ln;
END Closure.

And here is the output from OO2C:


martin at thinkpad:~/Code/Oberon$ oo2c --make Closure.Mod
martin at thinkpad:~/Code/Oberon$ cd bin
martin at thinkpad:~/Code/Oberon/bin$ ./Closure
1

which is correct.

However, here is the output of the same program (renamed to Closure.m so
the compiler accepts it) in the Oxford Oberon-2 Compiler (obc):


martin at thinkpad:~$ obc -o Closure Closure.m
"Closure.m", line 19: local procedure 'B' may not be used as a procedure
value
> A(2, B);
> ^

Why does it not allow B to be used as a procedure value?

After a little digging in the obc manual, I find a section that says:

    The scope of a procedure includes the bodies of all procedures
defined at the same nesting level, without the need for “forward
declarations”. In fact, such forward declarations are not permitted.

I’m guessing this is what is screwing it up, but I don’t really know
what that means.

Does anyone have an idea as to why oo2c seems to compile the code just
fine, and obc does not?


More information about the Oberon mailing list