Page 3 of 3
Re: Nested procedures
Posted: Wed Dec 11, 2013 1:57 pm
by augustk
If I understand it correctly even simple recursion in a local procedure like
Code: Select all
PROCEDURE P;
PROCEDURE Q;
BEGIN
...
Q
END Q;
BEGIN
Q
END P
is not allowed in Oberon-07/13.
Re: Nested procedures
Posted: Thu Dec 12, 2013 12:09 pm
by cfbsoftware
I can see why you ask - but it is allowed. While it is true that Q is declared locally in P, the identifier (in this case Q) that represents the name of a procedure is also visible in its own scope. Note that if that weren't true, the following would be possible:
Code: Select all
PROCEDURE Q;
VAR Q: INTEGER;
BEGIN
...
Q := 0;
END Q;
Re: Nested procedures
Posted: Fri Dec 13, 2013 9:38 am
by augustk
OK, I thought every identifier belonged to exactly one scope. Your example does make sense if that was the case.
Re: Nested procedures
Posted: Fri Dec 20, 2013 11:51 pm
by cfbsoftware
After working with Prof Wirth's latest Oberon for FPGA compiler, and receiving replies to a couple of questions I realise that my last reply, and probably some of my earlier posts in this discussion, were incorrect.
The following is actually legal Oberon code because PROCEDURE Q is a local variable in the outer scope:
Code: Select all
PROCEDURE Q;
VAR Q: INTEGER;
BEGIN
...
Q := 0;
The consequence of this is that you would not be able to call Q recursively
in this example.
Similarly (though unlikely to be seen in the real world) the following is also legal:
Code: Select all
PROCEDURE P2;
PROCEDURE P2;
BEGIN
...
END P2;
BEGIN
P2
END P2;
Again the call to P2 is not recursive as it refers to the local P2.
Therefore, for now, I am now planning to keep the behaviour of nested procedures and local objects the same as it was in Astrobe v4.5.