[Oberon] Oberon and closures

Bob Walkden bob at web-options.com
Thu Oct 30 09:16:10 MET 2008

> > So, yes, you can create a closure in Oberon.
> Well, no, not really.  The Module being a single giant closure over
> all the procedures defined in it is *not* what is generally meant by
> "closure".  In particular, languages which support closures generally
> allow something like this:
> MODULE Example;
> (* my oberon's a little rusty *)
>    Printer = PROCEDURE();
>    p, q: Printer;
> PROCEDURE CreateNumberPrinter(n: INTEGER): Printer;
>      PROCEDURE PrintingProcedure;
>      BEGIN Out.WriteInt(n)
>      END PrintingProcedure;
>      RETURN PrintingProcedure
> END CreateNumberPrinter;
>    p := CreateNumberPrinter(1);
>    q := CreateNumberPrinter(2);
>    p; (* prints 1 *)
>    q; (* prints 2 *)
> END Example;
> Note that each invocation of CreateNumberPrinter creates a new closure
> over the nested procedure PrintingProcedure. In fact the fact that
> Pascal/Modula/Oberon only allows top-level procedures as procedure
> values appears to be a direct result of the fact that the language
> doesn't support proper closures. (In order to support closures as
> above you need something more involved than a simple stack as an
> instance of PrintingProcedure needs to find its "n", even after the
> CreateNumberPrinter that created it is no longer active on the stack).

"the language doesn't support proper closures"

What are the benefits of supporting this? It doesn't feel to me as though it is
in 'the spirit of Oberon'. It feels like the kind of accident waiting to happen
that Prof. Wirth preferred to avoid.


More information about the Oberon mailing list