Official definition of call-by-value (Re: Finding the instance reference...)

greg greg at cosc.canterbury.ac.nz
Thu Nov 13 05:57:52 EST 2008


Fredrik Lundh wrote:

> Python's definition of the word "value" can be found in the language 
> reference:
> 
> http://docs.python.org/reference/datamodel.html#objects-values-and-types

That whole passage is talking almost
exclusively about the value of an *object*:

   Every object has an identity, a type and a value...
   ...possible values for objects of that type...
   The value of some objects can change...

etc. etc. But we don't want to know about the value of
an object, we want to know about the value of an
*expression*. That section doesn't tell us. Nor does
it tell us that expressions don't *have* values. It
says nothing about expressions at all.

 > Using that definition, a Python expression yields an object, not an
 > object value.

And as I've said before, that's a perfectly fine viewpoint.
Because,

   An assignment statement evaluates the expression list (remember that this can
   be a single expression or a comma-separated list, the latter yielding a tuple)
   and assigns the single resulting object to each of the target lists, from left
   to right.
 
[http://docs.python.org/reference/simple_stmts.html#grammar-token-assignment_stmt]

and what it says about binding makes it clear that assignment
is a form of binding operation.

So it doesn't matter *what* you call the result of an expression
-- a value, an object, an object reference, or whatever -- the
differences all cancel out when you define assignment in a
corresponding way.

-- 
Greg



More information about the Python-list mailing list