[fpc-pascal] "is"
Florian Klaempfl
F.Klaempfl at gmx.de
Thu Apr 7 22:26:12 CEST 2005
Thomas Schatzl wrote:
>
> Additionally if you examine code, _far_ the most applications do simple
> forward (and maybe backward) iteration over a collection (also because
> there are not that much collections where random access makes sense
> runtime-wise).
There come a lot in my mind: e.g. containers using internally trees
there "pre node" processing is cachewise usefull, "spare" sets,
containers using linked list to represent data internally etc.
>
> So maybe it is feasible to enhance the syntax to the following (BNF this
> time):
>
> foreachstatement ::=
> "foreach" element "in" container ["forwards" | "backwards"] "do"
> statement.
>
> or:
>
> foreachstatement ::=
> "foreach" element "in" typed-range-expression "do"
> statement.
>
> typed-range-expression ::=
> container "'" range-expression.
>
> range-expression ::= first-element-spec ".." last-element-spec.
>
> and first-element and last-element being a specification of those. This
> can be for arrays: bottom and last element (greetings from e.g.
> VHDL/ADA?, see for more details there), for OO containers a
> specification of two iterators indicating position, see STL.
> But this may be total overkill for the typical application.
>
> *ducks into cover, awaiting flames* =)
No, these ideas I like much more than a plain foreach statement. Though
I think implementing this using interfaces makes no use for me because
usually interfaces pulls in too much overhead so it doesn't scale very
well. Just look at the compiler, there are a lot of linked lists used like:
p:=first;
while assigned(p) do
begin
...
p:=p^.next;
end;
while the list in a lot of cases has only one element.
More information about the fpc-pascal
mailing list