[fpc-devel] Modernising Pascal

Anton Tichawa anton.tichawa at chello.at
Wed Feb 23 16:16:44 CET 2005


Jamie McCracken wrote:

> Marco van de Voort wrote:
>
>
>>
>>>>> 2. For Each. Its in Delphi 2005 and every modern language 
>>>>> implements it.
>>>>
>>>>
>>>>
>>>> Yeah, and I still wonder why. There is nothing to gain with it. 
>>>
>>>
>>> one less variable to manually declare
>>
>>
>>
>> Implement something in lazarus that auto-adds the variable to the 
>> local var
>> section. No need for language extensions.
>
>
> My mistake it actually avoids initialising the loop variable rather 
> than not declaring it:
>
> for i in myarray do
>   myarray[i] := 0;
>
> as opposed to
>
> for i := low(myarray) to high (myarray) do
>    myarray[i] := 0;
>
>
> I think the for..in is much clearer and more compact (it works for 
> sets, arrays and other enumerated types)
>
> jamie.
>
>> _______________________________________________
>> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
>> http://lists.freepascal.org/mailman/listinfo/fpc-devel
>>
>>
>
>
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
>
What about cases where the index should run from low(myarray) to 
pred(high(myarray)), e. g. when bubble-sorting? In such cases, you would 
still have to use the "classical" form, and end up with two different 
syntaxes.

And please note: It's often the more difficult, and more "intelligent" 
algorithms like sorting, comparison, ..., where i does -not- run from 0 
to n-1 but, e. g. from 0 to n-2.

I mean, the for-statement has a long but very clear syntax, and there's 
nothing superfluous in it. It's an assignment plus a bound, with an 
implicit increment.

Maybe in 90 % of the cases a "for i in blah" would be shorter, but you'd 
lose control over what actually happens, as the next step would probably 
be that the compiler may determine the direction or even order of the 
iterations.

IMHO, this general critics about losing control holds for your other 
proposals, too. Pascal is and will always be a -procedural- language 
with OO extensions, and is thus well suited for writing things like 
drivers or OSs, too; whereas your proposals, as far as I understand 
them, would lead to something like a compiled spreadsheet language like 
MS excel.






More information about the fpc-devel mailing list