Re: Effeciency of any predicate
- From: Vassil Nikolov <vnikolov+usenet@xxxxxxxxx>
- Date: 27 Feb 2007 18:58:46 -0800
On 27 Feb 2007 12:23:48 -0800, "S. Robert James" <srobertjames@xxxxxxxxx> said:
| 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)))))
By the way, I'd suggest to write the above using COND, rather than nest
OR within an IF, for better clarity and style (and note that ENDP is
better than NULL in Common Lisp when testing for the end of a list):
(defun anyp (predicate list)
(cond ((endp list) nil)
((funcall predicate (first list)))
(t (anyp predicate (rest list)))))
(untested).
---Vassil.
--
mind mate, n.
One of two persons mentally compatible with each other (cf. soul mate).
.
- References:
- Effeciency of any predicate
- From: S. Robert James
- Effeciency of any predicate
- Prev by Date: Re: Lisp Syntax - functions versus data
- Next by Date: Re: A style question
- Previous by thread: Re: Effeciency of any predicate
- Next by thread: Re: Effeciency of any predicate
- Index(es):
Relevant Pages
|