On Thu, Oct 27, 2022 at 11:38:57PM +0300, Jean Louis wrote: > * Drew Adams [2022-10-27 18:54]: > > In the worst case for your code, the first element IS non-nil and > > you spend forever doing useless stuff. In no case is your code as > > efficient as just testing each list element, starting at the > > beginning, and STOPPING as soon as you find a non-nil element. > > Of course I agree with the thought in general. > > Is it this below? > > (defun check-if-any-elt-is-non-nil (list) > (let (there-is) > (while (and list (not there-is)) > (when (car list) (setq there-is t)) > (setq list (cdr list))) > there-is)) If you are doing it "by hand", why not indulge in Lisp's "classic elegance", like so: (defun has-non-nil (lst) (cond ((null lst) nil) ((consp lst) (or (not (null (car lst))) (has-non-nil (cdr lst)))) (t (error "Not a proper list! You cheater!")))) Cheers -- t