Frank Heckenbach wrote:
Why not take the first occurence of a variable as the name to use on all output?
The first, or the most recent one, that's still a question. After some experimenting, there seem to be points for both ways. I'm implementing the latter now (though it should be easy to change). So, e.g.:
program Baz;
procedure Foo; var BaR: Integer; begin end;
begin WriteLn (bar) end.
will complain about an unknown identifier `bar', not `BaR' ...
That's quite natural, since the line in the main program _is_ the first occurence of `bar'. Outside procedure Foo, BaR isn't known at all.
But what about this case?
Program Baz;
Procedure Foo ( Bar: integer ); begin end;
begin foo; end.
... would complain about a missing parameter calling procedure `foo' in line 8. However, I'd rather talk about procedure `Foo' here, since this one's the line to look up in the source in order to get the correct routine's parameter list. (The line where the error occurred is already denoted in the error message: line 8.)
I'd generelly prefer to use the spelling of the _declaration_ of an identifier, not the spelling of a usage somewhere in the source. Which means: In your example, the error message still complains about an unknown identifier `bar' (since it's never declared in the context where it was used), but in my example we would get a message about incorrect use of `Foo' (spelling of the declaration).
Just one more example to complete the confusion:
Program Baz;
Procedure Foo; var bAR: integer; begin end;
Procedure BaR ( foo: integer ); begin end;
begin bar; end.
This one would, in my convention, complain about a missing parameter when calling procedure `BaR' (declaration), though this is neither the spelling of the first occurrence (local var), nor of the last occurrence (call). But I'd prefer the compiler to run like this, since it leads exactly to the right line when looking it up with a case-sensitive text search.
Yours,
Markus