Why not an __assign__ method?

Greg Ewing greg at cosc.canterbury.ac.nz
Fri Apr 6 00:33:27 EDT 2001


Carlos Alberto Reis Ribeiro wrote:
> 
> The proposal now is to call a predefined method, on the object that is the
> result of any expression, whenever the expression finishes being
> calculated.

I don't see how the compiler can know when the
expression has "finished being calculated", or
even whether this is a well-defined concept.

What you seem to want is to defer calling this
method as long as the compiler is sure that the
object cannot be aliased. But without knowing
anything about the objects concerned (which the
compiler doesn't) you can't ever be sure.
For example, in

  z = a + b + c

if the result of a + b is a class instance
with an __add__ method, then the second +
operation causes a Python function call which
aliases the intermediate object.

So I don't think it will be possible to do this
at compile time. Whatever is done will have to
be done dynamically at run time by something that
has detailed knowledge about the behaviour of the
operations that are being invoked, which would
seem to imply the objects themselves.

-- 
Greg Ewing, Computer Science Dept, University of Canterbury,	  
Christchurch, New Zealand
To get my email address, please visit my web page:	  
http://www.cosc.canterbury.ac.nz/~greg



More information about the Python-list mailing list