Evaluation order

Thierry Chappuis tchappui at gmail.com
Fri Jul 10 16:30:25 CEST 2015

Anyway, if we enter this kind of discussion, it is a reliable indication that
the code smells. There is a pythonic way to express the same task:

>>> t.sort()
>>> t

kind regards


On ven., juil. 10, 2015 at 2:28 PM, Terry Reedy < tjreedy at udel.edu [tjreedy at udel.edu] > wrote:
On 7/10/2015 8:04 AM, candide wrote:
> Le vendredi 10 juillet 2015 04:02:56 UTC+2, Chris Angelico a écrit :
>> I'm not sure what contradiction you're referring to, here. The
>> evaluation that you're pointing out says, as Terry showed via the
>> disassembly, that Python's first action is to look up the name 't' and
>> grab a reference to whatever object it points to.
> But in order to perform an operation, the interpreter has to evaluate
> the operands and "evaluating" is not "grabbing a reference to".

In the CPython, evaluating a name is implemented as getting the
reference corresponding to the name.

>> The execution of
>> t.sort() has to happen before the multiplication, because of the
>> parentheses.

> Official docs explains what evaluation is :
> When the name is bound to an object, evaluation of the atom yields that

Conceptually, that is exactly right. How that is implemented on a
computer in CPython is to load the address on the top of the virtual
machine stack.

> So, since the Python interpreter is performing evaluation from left to right,
> the first operand of the expression :
> t*(1+int(bool(t.sort())))
> evaluates to [2020, 42, 2015].

't' evaluates to the ***mutable*** list that 't' is bound to.

> Next, the second operatand evaluates to the integer 1.

And in the process of that evaluation, the list is sorted.

Terry Jan Reedy

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150710/4605199c/attachment.html>

More information about the Python-list mailing list