python list handling and Lisp list handling

Rhodri James rhodri at
Sat Apr 25 02:42:45 CEST 2009

On Sat, 25 Apr 2009 00:32:26 +0100, Mark Tarver  
<dr.mtarver at> wrote:

> OK; I think I get it.  RPLACA and RPLACD are part of the id of Common
> Lisp which I rarely contemplate.  However what it seems to be is that
> the difference is this. Lisp operates a destructive operation like
> RPLACA in such a way that RPLACA on a global G not only changes G, but
> all globals that reference G.  Python on the other hand has a
> destructive operation a[0] = .... which acts a bit like RPLACA but
> whose change is local to the global changed.  I take it that this is
> because Python essentially copies the list, creating a brand new
> vector rather than playing with pointers.  Is that more or less it?

In the specific case of list concatenation, Python copies the lists
being concatenated.  For other list operations this is not necessarily
true.  What is different is the concept of "all globals that
reference G".  For example:

>>> a = [1, 2, 3]
>>> b = a
>>> a[0] = 0
>>> print b
[0, 2, 3]

> Which brings me to my next question.  Assuming that we ban the use of
> destructive operations like a[0] = ... Lisp's RPLACA and all the
> rest.  Assuming the following Python encodings, and ignoring questions
> of performance, would Python and Lisp lists then be observationally
> indistinguishable? i.e. would these then be fair encodings?
> def car (x):
>   return x[0]
> def cdr (x):
>   return x[1:]
> def cons (x,y):
>   return [x] + y

I'm not sure you get a useful language by banning the destructive
operations.  In particular, list slicing is another copy operation,
so you're going to run into exactly the same set of problems.

Rhodri James *-* Wildebeeste Herder to the Masses

More information about the Python-list mailing list