Memory Leak ['LBBW': checked]

Terry Reedy tjreedy at udel.edu
Wed Feb 25 12:05:15 EST 2004


"Holger Joukl" <Holger.Joukl at LBBW.de> wrote in message
news:OF2B2CB932.A2F52747-ONC1256E45.004A4668-C1256E45.004E91A1 at lbbw.sko.de...

>2) I am quite stunned by the del alist[:] thing:
...
>alist[:] creates a shallow copy of alist,

The grammar for the delete statement is 'del <target>', not 'del
<expression>'.  Compare with assignment (binding) statements (which del
reverses): '<target> = <expression>'  The expression is fully evaluated.
The target is only evaluated to the extent needed to find the location for
the binding.  So 'del alist[:]' reverses 'alist[:] = <sequence>' and
'alist[:]' is handled the same for both.  To put it another way, del
<target> does the same thing that <target> = <expr> does before the latter
makes the assignment.

Given that function calls fully evaluate all arguements, while we do *not*
want targets evaluated to objects, assignment and del statements (and some
others) must be statements rather than functions.  (In Lisp, if you are
familiar with that, they would be special forms or macros.)

Terry J. Reedy







More information about the Python-list mailing list