[Python-ideas] Fast sum() for non-numbers - why so much worries?

Andrew Barnert abarnert at yahoo.com
Thu Jul 11 07:44:25 CEST 2013


On Jul 10, 2013, at 20:05, Joshua Landau <joshua at landau.ws> wrote:

>> E.g. I have a DSL where = reassigns to a data structure, += appends to an
>> existing one, and + is not defined at all. You can say "x += value" but not
>> "x = x + value". It makes sense in context. As I said, I am prepared to
>> consider that the right answer to this is "well don't call sum on your data
>> structure then", but it is a change in behaviour, not just an optimization.
> 
> That is... really quite a good argument. I think I may have to think
> on that final point, but you've probably just about won it. Why didn't
> you just say this from the start?

SymPy and another expression template library were already brought up earlier in the discussion. But I suspect most Python programmers have no experience with this kind of programming and/or have never heard of the libraries in question, and therefore had no idea what the point was until now.

SymPy does actually work with the add-once-then-iadd-to-that patch. I just tested summing together a list of symbolic expressions, and the result was the correct expression. Which makes sense, because it doesn't use __iadd__ anywhere (and in fact "x += y" rebinds x to the expression "x+y").

Anyway, thanks to Steven for explaining the point, and not using an example that fails to show what's intended. :)


More information about the Python-ideas mailing list