[fpc-devel] for-in-index loop

Alexander Klenin klenin at gmail.com
Fri Jan 25 17:18:00 CET 2013


On Fri, Jan 25, 2013 at 7:07 PM, Michael Van Canneyt
<michael at freepascal.org> wrote:
> WITH EACH ADDITIONAL "FEATURE" WE ARE BUTCHERING PASCAL MORE AND MORE.
Hm... Do not you think this is a bit of an overstatement?

> There are plenty to choose from. He said maybe he'd look after fcl-stl. The
> silence since was deafening.
"for-in-index" extension was actually planned by me as a prerequisite
for fcl-stl work.
I did some experiments with the current implementation, even discussed
it at a conference
related to teaching of algorithmic programming to children.
As I have already explained, main competition in this area now comes
from Python and
other dynamic languages. While discussing container access in Pascal vs Python,
lack of "for-in-index" was brought up by attendees as one of Pascal's
weaknesses.

> He said he needed a arbitrary precision math library: Well, get started !
I have chosen a good library, communicated with the author, and he
agreed (on this list)
to allow its inclusion in FPC. Now somebody (not me, since I do not
have commit rights)
should perform the addition.

> Both should be perfectly within grasp of a student.
> If he has students, let them work on that.
Unfortunately there are specific requirements for this type of student work
(it is approximately equivalent to bachelor's thesis).
"A single large new feature" is much better suited to it then
"polishing the library, with many small refactorings and improvements".
Note that for Vasily, "for-in-index" if not actually this "large feature",
it was chosen by me as a relatively minor and simple feature to introduce him
to the code base and the community.
I am sorry that the community turned out not quite welcoming.

> Pascal needs more useful libraries.
It is important to note that default libraries ARE part of the language,
and from the user's POV language vs library distinction is an irrelevant detail.
What is important is a clear, concise and easy-to-remember syntax.

With this in mind, consider a user who wants to iterate over the
following array:

var
  a: array [1..5] of Integer = (1, 2, 9, 4, 5);

In my proposal, he should write:
var
  v, i: Integer;
begin
  for a in a index i do
    Writeln(i, ' ', v);
end.

In your proposal, he should write (suppose GIter is a unit
implementing the generic array iterator):
uses
  GIter;
type
  TArrayIntIterator = specialize TArrayIterator<Integer>;
  i: TArrayIntIterator.TElem;
begin
  for i in TArrayIntIterator.Create(a) do
    Writeln(i.Index + Low(a), ' ', i.Value);
end.

Now my point is that second variant is harder to learn and understand
then the first one,
regardless of the fact that is uses "simpler" language.
And yes, I have code for the second example in my working copy of
improved fcl-stl.

--
Alexander S. Klenin



More information about the fpc-devel mailing list