if does not evaluate

Jim Newton jimka at rdrop.com
Fri Jun 11 07:13:59 CEST 2004


> (define has-element (cond list) 
>     (equal () (member-if #'cond list))))
> 
> Well, it's definitely short.  It doesn't exactly translate well,
> though; search the list for a sub-list that starts with an element
> which evaluates to true under cond.  Evaluate to the equality of that
> list with the null list.  Hmmm.
> 

Not sure what you mean by "does not translate well?"  Although maybe
i misunderstand, but it looks like you are naming the function the
opposite of what it does?

(define has-not-element ( cond list)
    (null (member-if #'cond list)))

Are you really trying to find out whether the condition fails
for every element of the list?

By the way, how do you find out in Python if there is
a member of a list that matches a condition?  It is something
i often and never know the best way to do it?  I can
use a list compression to find ALL the matches, but what
if i only want to know whether or not there is a match?

-jim




More information about the Python-list mailing list