[Python-Dev] Re: accumulator display syntax

Aahz aahz at pythoncraft.com
Fri Oct 24 16:20:51 EDT 2003


On Wed, Oct 22, 2003, Guido van Rossum wrote:
>
> I think that for reductions the gains are less clear.  The initializer
> for the result variable and the call that updates its are no longer
> boilerplate, because they vary for each use; plus the name of the
> result variable should be chosen carefully because it indicates what
> kind of result it is (e.g. a sum or product).  So, leaving out the
> condition for now, the pattern or idiom is:
> 
>   <result> = <initializer>
>   for <variable> in <iterable>:
>       <result> = <expression>
> 
> (Where <expression> uses <result> and <variable>.)

Actually, even that doesn't quite capture the expressiveness needed,
because <expression> needs in some cases to be a sequence of statements
and there needs to be an opportunity for a finalizer to run after the for
loop (e.g. average()).
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"It is easier to optimize correct code than to correct optimized code."
--Bill Harlan



More information about the Python-Dev mailing list