emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: lists, plain conses and length


From: tomas
Subject: Re: lists, plain conses and length
Date: Fri, 4 Sep 2020 10:53:30 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

On Fri, Sep 04, 2020 at 04:29:47AM +0200, Lars Ingebrigtsen wrote:
> "T.V Raman" <raman@google.com> writes:
> 
> > (length a)=> Debugger entered--Lisp error: (wrong-type-argument listp 2)
> >
> > Q: how does one distinguish a cons from a list.
> > The error  message for length may need fixing since it says the
> > argument passed to it is not a list (it's correct) but then listp is wrong?
> 
> `length' (and many other functions) require what's called a "proper
> list", which simply means that the cdr of the last cons cell is nil.
> 
> (length '(1 2 . 3))
> -> (wrong-type-argument listp 3)
> 
> The predicate to use here is `proper-list-p'.

Note that `proper-list-p' has to run down the whole list to make
sure. For short lists, that's fine.

Cheers
 - t

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]