[Oberon] Procedure variables and local procedures
Andreas Pirklbauer
andreas_pirklbauer at yahoo.com
Fri Sep 29 12:04:20 CEST 2017
> On 2017-09-28 21:15, August Karlstrom wrote
> > On 2017-09-28 18:57, Andreas Pirklbauer wrote:
> > Addendum: Another way to read the sentence “P must not be declared local to ANOTHER
> > procedure” is that in fact “P may be declared local to the SAME procedure”.
>
> Your interpretation seemed far fetched at first, but you are most likely right. I get it now.
>
> -- August
In fact, with the latest revision of Oberon-07 one could rewrite the above language rule as “If a procedure P is assigned to a procedure variable v, both v and P must be visible in the scope where the assignment is made and when it is made”.
Thus, Oberon-07 now no longer *require*s the enclosing scope of a local procedure P to be active when P is executed. P only needs to be “reachable somehow”, and this could be via a global variable, as shown below. However I would not recommend adopting such a programming pattern (the example is just meant to show what is now “legally possible”). This may be why this new “feature" is advertised anywhere. It can be seen a byproduct of the decision to restrict access to variables on the global or the strictly local level. This eliminated the need for a static link in implementations. And this in turn means that the enclosing scope doesn’t have to be around anymore when a procedure P is executed.
-Andreas
MODULE M;
TYPE Proc = PROCEDURE;
VAR GlobalVar: Proc;
PROCEDURE GlobalProc1;
VAR LocalVar1: Proc;
PROCEDURE LocalProc1; BEGIN END LocalProc1;
BEGIN (*GlobalProc1*)
END GlobalProc1;
PROCEDURE GlobalProc2;
VAR LocalVar2: Proc;
PROCEDURE LocalProc2; BEGIN END LocalProc2;
BEGIN (*GlobalProc2*)
GlobalVar := GlobalProc1; (*allowed*)
GlobalVar := GlobalProc2; (*allowed*)
GlobalVar := LocalProc2; (*allowed (LocalProc2 visible in current scope)*)
LocalVar2 := GlobalProc1; (*allowed*)
LocalVar2 := GlobalProc2; (*allowed*)
LocalVar2 := LocalProc2; (*allowed (LocalProc2 visible in current scope)*)
(*
GlobalVar := LocalProc1; (*not allowed (LocalProc1 undefined)*)
LocalVar1 := GlobalProc1; (*not allowed (LocalVar1 undefined)*)
LocalVar1 := GlobalProc2; (*not allowed (LocalVar1 undefined)*)
LocalVar1 := LocalProc1; (*not allowed (LocalVar1 and LocalProc1 undefined)*)
LocalVar1 := LocalProc2; (*not allowed (LocalVar1 undefined)*)
*)
END GlobalProc2;
BEGIN (*M*)
GlobalVar := GlobalProc1; (*allowed*)
GlobalVar := GlobalProc2; (*allowed*)
GlobalVar; (*allowed*)
GlobalProc2; (*allowed (assigns LocalProc2 to GlobalVar)*)
GlobalVar; (*allowed (effectively executes LocalProc2) !!!*)
(*
GlobalVar := LocalProc1; (*not allowed (LocalProc1 undefined)*)
GlobalVar := LocalProc2; (*not allowed (LocalProc2 undefined)*)
LocalVar1 := GlobalProc1; (*not allowed (LocalVar1 undefined)*)
LocalVar1 := GlobalProc2; (*not allowed (LocalVar1 undefined*)
LocalVar1 := LocalProc1; (*not allowed (LocalVar1 and LocalProc1 undefined)*)
LocalVar1 := LocalProc2; (*not allowed (LocalVar1 and LocalProc2 undefined)*)
LocalVar2 := GlobalProc1; (*not allowed (LocalVar2 undefined)*)
LocalVar2 := GlobalProc2; (*not allowed (LocalVar2 undefined*)
LocalVar2 := LocalProc1; (*not allowed (LocalVar2 and LocalProc1 undefined)*)
LocalVar2 := LocalProc2; (*not allowed (LocalVar2 and LocalProc2 undefined)*)
*)
END M.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.inf.ethz.ch/pipermail/oberon/attachments/20170929/de504cfd/attachment.html>
More information about the Oberon
mailing list