[fpc-devel] New feature discussion: for-in loop

Micha Nelissen micha at neli.hopto.org
Sat Oct 31 13:32:21 CET 2009


Vinzent Hoefler wrote:
> 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?

It can't. In general, all references to the (iterator) list need to be 
"const" at this time, but I guess it's impossible to prove whether some 
reference is a reference to the particular list being iterated. Let 
alone a function that "might" be called by an iterating for-in loop.

> 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).

That solution seems too costly to me.

Micha



More information about the fpc-devel mailing list