[fpc-devel] New feature discussion: for-in loop
Vinzent Hoefler
JeLlyFish.software at gmx.net
Sat Oct 31 13:12:59 CET 2009
On Monday 26 October 2009, Micha Nelissen wrote:
> Vinzent Höfler wrote:
> > At first, "const function" would tell us that the function does not
> > change the object in any way, right?
>
> What is "the object"?
In that case, the list, of course.
> Usually there are 2 objects: the list (TList
> e.g.) and the object being iterated, e.g. TList.Objects[I]. Those
> referenced objects can be volatile, the const-ness only applies to
> the TList.
Yes, that's what I thought.
> Ideally the iterator state and the state of the items
> iterated over are separated. (Maybe this is not so with e.g.
> TStringList).
Suppose, the list items have a property "Owner" and the iterator calls
some method that says "Owner.Delete (self);" somewhere. How's the
compiler supposed to detect that?
In some languages, this problem is circumvented by creating a copy of
the list before iterating the set, but I don't think that this is a
viable solution for Pascal (or any compiled language, for that matter).
Vinzent.
More information about the fpc-devel
mailing list