On 06/18/11 00:45, Franck Ditter wrote:
Hi, I'm just wondering about the complexity of some Python operations
to mimic Lisp car and cdr in Python...
def length(L) :
if not L : return 0
return 1 + length(L[1:])
Should I think of the slice L[1:] as (cdr L) ? I mean, is the slice
Lie Ryan wrote:
On 06/18/11 00:45, Franck Ditter wrote:
Hi, I'm just wondering about the complexity of some Python operations
to mimic Lisp car and cdr in Python...
def length(L) :
if not L : return 0
return 1 + length(L[1:])
Should I think of the slice L[1:] as (cdr L) ? I mean
On Sun, Jun 19, 2011 at 10:56 PM, Ethan Furman et...@stoneleaf.us wrote:
Lie Ryan wrote:
def cdr(L):
return L[1]
IANAL (I am not a Lisper), but shouldn't that be 'return L[1:]' ?
In LISP, a list is a series of two-item units (conses).
L = (a, (b, (c, (d, None
This represents the
On Sun, 19 Jun 2011 05:56:27 -0700, Ethan Furman wrote:
Lie Ryan wrote:
On 06/18/11 00:45, Franck Ditter wrote:
Hi, I'm just wondering about the complexity of some Python operations
to mimic Lisp car and cdr in Python...
def length(L) :
if not L : return 0
return 1 + length(L[1
On Sun, 19 Jun 2011 15:56:27 +0300, Ethan Furman et...@stoneleaf.us wrote:
Lie Ryan wrote:
def length(L):
if not L: return 0
return 1 + length(cdr(L))
How is this different from regular ol' 'len' ?
It's better, because len() can't overflow the stack. ;)
--
Ethan Furman et...@stoneleaf.us writes:
def car(L):
return L[0]
def cdr(L):
return L[1]
IANAL (I am not a Lisper), but shouldn't that be 'return L[1:]' ?
Not for the linked list implementation he presented.
def length(L):
if not L: return 0
return 1 + length(cdr(L))
Ethan Furman wrote:
IANAL (I am not a Lisper), but shouldn't that be 'return L[1:]' ?
Ah, thanks all for the clarification.
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
On 6/19/2011 9:24 AM, Steven D'Aprano wrote:
No. Each cell in a Lisp-style linked list has exactly two elements, and
in Python are usually implemented as nested tuples:
(head, tail) # Annoyingly, this is also known as (car, cdr).
where head is the data value and tail is either another
* 2011-06-19T12:20:32-04:00 * Terry Reedy wrote:
On 6/19/2011 9:24 AM, Steven D'Aprano wrote:
No. Each cell in a Lisp-style linked list has exactly two elements,
and in Python are usually implemented as nested tuples:
(head, tail) # Annoyingly, this is also known as (car, cdr).
where head
On Fri, 17 Jun 2011 16:45:38 +0200, Franck Ditter wrote:
Hi, I'm just wondering about the complexity of some Python operations
to mimic Lisp car and cdr in Python...
def length(L) :
if not L : return 0
return 1 + length(L[1:])
Python's lists are arrays/vectors, not linked lists
Hi, I'm just wondering about the complexity of some Python operations
to mimic Lisp car and cdr in Python...
def length(L) :
if not L : return 0
return 1 + length(L[1:])
Should I think of the slice L[1:] as (cdr L) ? I mean, is the slice
a copy of a segment of L, or do I actually get
On Fri, Jun 17, 2011 at 8:45 AM, Franck Ditter fra...@ditter.org wrote:
Hi, I'm just wondering about the complexity of some Python operations
to mimic Lisp car and cdr in Python...
def length(L) :
if not L : return 0
return 1 + length(L[1:])
Should I think of the slice L[1:] as (cdr L
12 matches
Mail list logo