On Fri, Sep 04, 2020 at 04:29:47AM +0200, Lars Ingebrigtsen wrote: > "T.V Raman" 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