Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.06; 'forth.': 0.07; 'slice': 0.07; 'terry': 0.07; 'python': 0.08; 'none)': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'tail': 0.09; 'tuple': 0.09; 'am,': 0.14; 'wrote:': 0.14; 'elements,': 0.16; 'lisp': 0.16; 'one-element': 0.16; 'reedy': 0.16; 'jan': 0.20; 'header:In-Reply-To:1': 0.21; 'structure': 0.23; 'point,': 0.25; 'subject: : ': 0.26; '(as': 0.29; 'nested': 0.30; 'usually': 0.32; 'steven': 0.32; 'header:X-Complaints-To:1': 0.32; 'to:addr :python-list': 0.33; 'list': 0.33; 'actually': 0.33; '(for': 0.33; 'there': 0.35; 'header:User-Agent:1': 0.35; "d'aprano": 0.35; 'list:': 0.36; 'element': 0.37; 'sequence': 0.37; 'another': 0.37; 'two': 0.37; 'received:org': 0.38; 'could': 0.38; 'but': 0.38; 'data': 0.38; 'implemented': 0.38; 'linked': 0.38; 'subject:: ': 0.38; 'should': 0.39; 'empty': 0.39; 'header:Mime-Version:1': 0.39; 'either': 0.39; 'to:addr:python.org': 0.39; 'more': 0.60; 'as:': 0.71; 'marker': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Python and Lisp : car and cdr Date: Sun, 19 Jun 2011 12:20:32 -0400 References: <4dfd90de$1@dnews.tpgi.com.au> <4dfdf896$0$30002$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: rain.gmane.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10 In-Reply-To: <4dfdf896$0$30002$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1308500442 news.xs4all.nl 49183 [::ffff:82.94.164.166]:38360 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7979 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 Lisp-style list > or a marker for empty (such as the empty tuple () or None). > > So a one-element linked list might be given as: > > (42, None) > > A two element list: (42, (43, None)) > Three element list: (42, (43, (44, None))) > > and so forth. So while you could harmlessly use a slice L[1:], there is > no point, since L[1:] will have at most a single element. It should be noted that the head element of any 'list' can also be a 'list' (as with Python lists), t = { { (1,None), (2,(3,None)) ), ( (4,(5,None)), (6,None) ) ) so that the structure is actually a tree, which is a much more general data structure than a true sequence of atoms. But TREP (for tree-processing) is not as catchy as LISP (for list processing). -- Terry Jan Reedy