Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion (endp lst) or (null lst)

User-Agent: Microsoft-Entourage/10.1.1.2418
Date: Sat, 04 Jan 2003 09:15:09 -0700
Subject: Re: (endp lst) or (null lst)
From: Chris Gehlker <gehl...@fastq.com>
Newsgroups: comp.lang.lisp
Message-ID: <BA3C569D.25519%gehlker@fastq.com>
References: <BA3BB319.25505%gehlker@fastq.com> <3250662317762335@naggum.no>
Mime-version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-transfer-encoding: 8bit
NNTP-Posting-Host: 65.39.88.254
X-Trace: corp.newsgroups.com 1041696865 65.39.88.254 (4 Jan 2003 10:14:25 -0600)
Lines: 52
X-Comments: This message was posted through Newsfeeds.com
X-Comments2: IMPORTANT: Newsfeeds.com does not condone, nor support,  spam or any illegal or copyrighted postings.
X-Comments3: IMPORTANT: Under NO circumstances will postings containing illegal or copyrighted material through this service be tolerated!!
X-Report: Please report illegal or inappropriate use to <ab...@newsfeeds.com>
X-Abuse-Info: Please be sure to forward a copy of ALL headers, INCLUDING the body (DO NOT SEND ATTACHMENTS)
Organization: Newsfeeds.com http://www.newsfeeds.com 80,000+ UNCENSORED Newsgroups.
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!news-out.newsfeeds.com!l2!corp.newsgroups.com!not-for-mail

On 1/4/03 2:45 AM, in article 3250662317762...@naggum.no, "Erik Naggum"
<e...@naggum.no> wrote:

> * Chris Gehlker <gehl...@fastq.com>
> | Comes Stephen Slade to say that the canonical way to test for the
> | end of proper list lst is (endp lst) rather than (null lst).  The
> | HyperSpec seems to agree.  And yet I have the impression that
> | almost no one uses endp.
> 
> Almost nobody uses dotted lists to begin with, so why should they
> think of using `endp´?
> 
> Give a function that traverses a list naïvely and tests with `null´
> a dotted lists and it will most probably stumble on the `cdr´ that
> gets a non-cons argument at the end of the list.  In all likelihood
> the program will enter the debugger or terminate ungracefully.
> 
> A much more robust way is not to test for the end of the list at
> all, but to test for a cons cell that would require more traversal.
> 
> Take the infinitely silly Scheme-like example of computing `length´
> with a maximum of gratuitous overhead:
> 
> (defun length (list)
> (if (cons list)
>   (1+ (length (cdr list)))
>   0))
> 
> compared to the seemingly very similar:
> 
> (defun length (list)
> (if (null list)
>   0
>   (1+ (length (cdr list)))))
> 
> The cdr chain of a proper list is certainly terminated by an atom
> that is `nil´, but unless you explicitly attach significance to the
> specific atom that is the cdr of the last cons, should you care so
> much as to signal an error if it is not the canonical `nil´ or are
> you no worse off if you simply ignore it?  It is sloppy to pass
> anything non-`nil´ to `cdr´; careful programming demands that you
> know that you pass `cdr´ a cons cell.

Either I'm very confused or the examples are in the wrong order (or both).
It seems more efficient to to simply test with consp and avoid examining the
terminal cons.



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----