Message from discussion (endp lst) or (null lst)
Date: Sat, 04 Jan 2003 09:15:09 -0700
Subject: Re: (endp lst) or (null lst)
From: Chris Gehlker <gehl...@fastq.com>
References: <BA3BB319.email@example.com> <firstname.lastname@example.org>
Content-Type: text/plain; charset="ISO-8859-1"
X-Trace: corp.newsgroups.com 1041696865 126.96.36.199 (4 Jan 2003 10:14:25 -0600)
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.
On 1/4/03 2:45 AM, in article 3250662317762...@naggum.no, "Erik Naggum"
> * 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)))
> compared to the seemingly very similar:
> (defun length (list)
> (if (null list)
> (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
-----= 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! =-----