[fpc-devel] New feature discussion: for-in loop
"Vinzent Höfler"
JeLlyFish.software at gmx.net
Mon Oct 26 19:47:28 CET 2009
Micha Nelissen <micha at neli.hopto.org>:
> Vinzent Höfler wrote:
> > Von: Micha Nelissen <micha at neli.hopto.org>
> >> That's why I suggested the use of 'const functions' in other message in
> >> this thread.
> >
> > Yes, I read that later on. Is that implemented in FPC?
>
> I don't think so; but I think it would be a useful part of the iterator
> proposal. The iterator case really gives it some strength.
I thought about it [no, not that long I needed to answer this mail...] and there are certain issues with this:
At first, "const function" would tell us that the function does not change the object in any way, right? But this is bad for an iterator: Suppose, you want to replace some value in your iteration set, it wouldn't be allowed via the "const function" and calling "non-const" functions wouldn't be allowed inside the for-loop, because it could destabilize the iterator.
For an iterator to work properly, the called functions should guaranteed that neither size nor order (perhaps in a stronger version) of the iterated set does change. Other values can be changed without problems, so the garantees made by a "const"-function would be too strong here, I think...
> If not used
> by other features it may seem more like a "OO-purity" thing (although
> that is not per definition bad) ;-).
It could easily be used as optimization. :) If the function is constant (and does not access global variables), its result can be replaced by the result of a previous call with the same argument (IOW: some notion of a "pure" function).
Vinzent.
--
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/chbrowser
More information about the fpc-devel
mailing list