python list handling and Lisp list handling
Arnaud Delobelle
arnodel at googlemail.com
Fri Apr 24 14:54:34 EDT 2009
Mark Tarver <dr.mtarver at ukonline.co.uk> writes:
> Ah; so this
>
> def cons (x,y):
> return [x] + y
>
> is not accurate?
Depends what you mean by accurate!
in lisp, if you do:
(setq a '(1 2))
(setq b (cons 0 a))
(rplaca a 3)
Then
a is now (3 2)
b is now (0 3 2)
In Python, if you do:
a = [1, 2]
b = cons(0, a) # with your definition of cons
a[0] = 3
Then
a is now [3, 2]
b is now [0, 1, 2]
So in this respect, it is not accurate. But that's because Python lists
are vectors not conses.
--
Arnaud
More information about the Python-list
mailing list