Eike Lange wrote:
On Wed, Dec 04, 2002 at 05:56:09AM -0800, Frank D. Engel, Jr. wrote:
It is exactly as it should be. In the first declaration, you redefine 'Integer' to be a variable, not a type. Then when you reach the second one (for 'Real'), Integer is no longer a type, and you get an error. In your second form, 'Integer' is still a type, since both variables are being defined simultaniously. Therefore that one works.
I ever thought, that all things right of the colon must be types. Therfore, my example is right. A redifinition of a type is IMO of the following form:
type Integer = Cardinal (7);
Where var Integer: Integer; defines a vaiable called "Integer" of type Integer, which is completly different.
Question: Why would you want to do this anyway? It is confusing.
I just wanted to test this feature. Never thought of using it in "real programs", but it should be possible.
Maybe you had the idea that an identifier could have different meanings as a type and a variable at the same time. That's not so. In Pascal, an identifier can have (at most ;-) one meaning in a scope, so when it's declared as a variable, the type declaration is "shadowed".
In your second form, 'Integer' is still a type, since both variables are being defined simultaniously. Therefore that one works.
Actually, I'm not sure. I'd have to check the standards again, but ISTR that an identifier cannot in one scope be used with an outer-scope meaning and be redefined. So if I'm not mistaken, GPC is not correct -- the second example should also fail. (But this might be harder to fix ... one might have to flag each identifier which is used in the current scope, so a later redeclaration in the same scope could be recognized as erroneous ...)
If I were writing a Pascal compiler, I would be tempted to make some of these identifiers into keywords, for this very reason. Of course, then I would not meet the Pascal standards...
Well, I wouldn't try this. We have enough problems with actual keywords from different standards/dialects (most prominently proably `value' which is a keyword in EP, but is often used as an identifier otherwise).
And if you think noone would ever want to redefine `Integer' ... well, for very strict BP compatiblity we even have to do this (define it as a 16 bit type, though only in the `System' unit with a special conditional) ...
Frank