[PYTHON MATRIX-SIG] More on Less Copying

Fredrik Lundh fredrik_lundh@ivab.se
Tue, 11 Mar 1997 19:53:06 +0100


> I don't know if his opinions have changed lately, but at the Livermore 
> workshop, Guido expressed a definite willingness to consider += operators. 

>From the archives...

> > How about providing assignment operators? Some time one has to
> > build a thing piece-meal and this sort of operators are very
> > handy. The semantics are clear:
> >
> > <var> <op>= <expr> === <var> = <var> <op> <expr>
> >
> > Example:
> >  a = 'ba '
> >  a *= 2 # a = 'ba ba'
> >  a += 'black sheep' # a = 'ba ba black sheep'
>
> Agreed. Now that the parser can actually recognize two-character
> operators, adding these wouldn't be so hard (except that the grammar
> tables will grow again :-( ).
>
> > I would also like the capability of overloading standard operators
> > for predefined and user defined classes. Thus instead of
> >  result.append(b)
> > I should be able to say
> >  result += b
> > or better still,
> >  result += [a,b,c]
>
> The latter should automatically work if we let x += y be syntactic
> sugar for x = x+y. Note that result = result + [x] has a different
> meaning than result.append(x), although in many cases it doesn't
> matter: result.append(x) modifies the existing object that result is
> bound to, while result = result+[x] creates a new list (the
> concatenation of result and [x]) and binds result to it, forgetting
> the object to which result was bound previously. If there was another
> reference to that object, e.g., through an assignment "z = result"
> earlier on, the value of z is unchanged by the second form, but
> modified by the first form. Confusing? Yes, but this is a lot better
> than allowing arbitrary pointers!

(November 1991)

We're still waiting ;-)

Cheers	/F (http://hem1.passagen.se/eff)

_______________
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________