[fpc-devel] Pascal Standard, and what we can do.

Mark Morgan Lloyd markMLl.fpc-devel at telemetry.co.uk
Thu Jul 23 01:08:59 CEST 2015

Steve Smith wrote:
> On 22/07/15 19:20, Paul van Helden wrote:
>> I have never managed to understand why "declare before use" is so 
>> important
>> to Pascal. I get the bit about strong typing and doing everything 
>> possible
>> to eliminate errors at compile time, but I still don't get why. If 
>> this is
>> central to what makes something "Pascal", I would love to be pointed to a
>> good explanation. I'm not trying to be a pain here. I've been programming
>> in Pascal, full time, for most of my life. It has always puzzled me why
>> everything has to be declared first.
> Consider the following code:
> procedure Test;
> var i : integer;
> begin
>   for J := 1 to 25 do
>     writeln;
> end;
> With "Declare before use", this is plainly incorrect. J has not been 
> declared; You can't type; You are an idiot!

Since the value of J is undefined at the normal exit of a for loop, one 
might be tempted to allow implicit definition. But what about this case:

for j := 0 to 24 do
   if j = 12 then

What is j here, and what would it be if an implicit j were defined which 
only had the scope of the loop?

The whole issue of variable declarations appearing before  begin  is 
central to the distinction between ALGOL (and derivatives including C) 
and Pascal (and derivatives including Modula). A related issue is 
whether a variable's type appears before (ALGOL, C) or after (Pascal, 
Modula) its name.

Another issue is whether  if...then  is followed by a single statement 
(ALGOL 60, Pascal) or by multiple statements followed by  fi  or  end 
(ALGOL 68, Modula). And then there's  x := if...then...else...;  which 
exists in ALGOL and (in a more compact form) in C, but not in Pascal and 
its derivatives.

And those are the shibboleths by which Pascal are recognised.

Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]

More information about the fpc-devel mailing list