Path: utzoo!attcan!uunet!husc6!uwvax!rutgers!orstcs!ruffwork From: ruffwork@orstcs.CS.ORST.EDU (Ritchey Ruff) Newsgroups: comp.lang.lisp Subject: list-length vs. listp in Common Lisp? Message-ID: <6317@orstcs.CS.ORST.EDU> Date: 5 Sep 88 17:37:14 GMT Reply-To: ruffwork@CS.ORST.EDU (Ritchey Ruff) Organization: CS Dept, Oregon State University, Corvallis Lines: 25 Anyone notice how hard it is to make sure you pass a "true" list to list-length (or length)? I know CLtL says that (LISTP ) will not tell a doted-list from a true-list, but then if you test for a list with listp and it returns "t" you still may get an error from "list-length" saying "arg not a list" (boy, did this ever make a lot of sense when I first had it happen to me ;-). The only way I've found to make sure an arg is a true list is with - (defun true-listp (l) (and (listp sexp) (null (cdr (last l))))) but then it's easier to write my own version of list-length and add an extra termination condition for dotted endings. (I want to know how many data items are in the list so that I can precess them, so (1 2 3 4 5 . 6) is length 6 and (1 2 3 4 5) is length 5, etc.) it would be nice if you could do something like (list-length sexp :doted-ending-allowed) Isn't there an easier way? (now watch, even though I just spent over an hour pouring through Steele somebody will say, "Oh, that's the function called true-listp on page xyz of CLtL...;-). --ritchey ruff ruffwork@cs.orst.edu -or- ...!tektronix!orstcs!ruffwork "I haven't lost my mind, it's backed up on tape somewhere..."