On Friday, 20 March 2015 at 20:31:49 UTC, Walter Bright wrote:
On 3/20/2015 3:59 AM, Paulo Pinto wrote:
On Friday, 20 March 2015 at 10:50:44 UTC, Walter Bright wrote:
Since 'line' is never referred to again after constructed,
even a simple
optimizer could elide it.
It would be easy to test - accumulate the lines in an array,
and check the times.
Which the default Python implementation doesn't have, hence my
comment.
After all these years, the default Python implementation
doesn't do fairly basic optimizations? I find that a bit hard
to believe.
Also even if it did have one, it cannot elide it as it cannot
guarantee the
semantics of the generators/iterators side effects will be
kept.
I wonder why keeping a string would be a side effect.
I'm not saying you're wrong, I don't know Python well enough to
make such a judgement. It just causes me to raise one eyebrow
like Spock if it does work this way.
The side effect is not keeping the string, rather generating it.
for var in exp:
do_something()
if exp represents a iteratable or a generator, even if var is
thrown away the loop needs to be preserved to keep the semantics
of calling next() on the instance object that executes the
for..in loop.
Put other way, does DMD throw away foreach loops even if the
compiler cannot prove if opApply () or popFront() generate side
effects, assuming the variable isn't being used?
--
Paulo