Re: Effeciency of any predicate



S. Robert James schrieb:
Is there a more efficient way of doing this:

(defun any? (predicate lst)
(if (null lst)
nil
(or (funcall predicate (car lst))
(any? predicate (cdr lst)))))

Does common Lisp have a built in which can reach the same goal?

Others toly you about SOME, but you could also say:

(defun any (predicate list)
(when list
(or (funcall predicate (first list))
(any predicate (rest list)))))


André
--
.



Relevant Pages

  • Re: Partition list with predicate
    ... | I want a function that removes values from a list if a predicate ... If you must modify the list in place, because you have multiple references ... lst = ...
    (comp.lang.python)
  • Re: Effeciency of any predicate
    ... (defun any? ... (predicate lst) ... (or (funcall predicate (car lst)) ... Does common Lisp have a built in which can reach the same goal? ...
    (comp.lang.lisp)
  • Re: Effeciency of any predicate
    ... (predicate lst) ... (or (funcall predicate (car lst)) ... There is also an equivalent in the loop macro, ... In Common Lisp, it's unusual to use the question mark to indicate predicates. ...
    (comp.lang.lisp)
  • Effeciency of any predicate
    ... (predicate lst) ... (or (funcall predicate (car lst)) ... predicate (cdr lst))))) ...
    (comp.lang.lisp)
  • Re: Partition list with predicate
    ... Terry Reedy wrote: ... | I want a function that removes values from a list if a predicate evaluates ... Forget the rigamarole you posted, ... lst = ...
    (comp.lang.python)