On Wed, Jan 29, 2003 at 10:18:19PM +0100, Frank Heckenbach wrote:
Emil Jerabek wrote:
On Wed, Jan 29, 2003 at 02:03:57AM +0100, Frank Heckenbach wrote:
Consider the following situation:
program Foo;
function a: Integer;
function a: Integer; begin a := 42 end;
begin a := a end;
begin WriteLn ('OK') end.
The problem here is that within the outer `a', the identifier `a' can mean both its result variable and the local function `a'.
IMHO function heading does _not_ declare the function name as a real variable identifier.
Yes, it's a "functionÂidentifier" in terms of the standard.
It is allowed _only_ on the left-hand side of an assignment statement.
OK (6.9.2.2).
Anywhere else it behaves according to the usual Pascal scoping rules: in general this means a recursive call (because the name is defined in outer scope as a function identifier), but in the example above, it is shadowed by the local function declaration. (This is legal, because the scopes are different.)
But still the identifier `a' would refer to both functions (as a functionÂidentifier) on the left and right sides of the same statement?
On second sight, I'm not sure at all. The right side refers to the local function. As for the left side, I assumed in my first reply that it refers to the result variable, because it can't mean anything else (a call to the local `a' is not an lvalue), but this explanation fails in other situations:
function a: Integer;
var a: Integer;
begin a := 42 end;
It seems logical that such a local declaration shadows the outer function-identifier `a' completely (hence both examples are invalid).
Emil