if does not evaluate
moughanj at tcd.ie
Sat Jun 12 07:00:32 CEST 2004
Jim Newton <jimka at rdrop.com> wrote in message news:<2it0kiFqud3kU1 at uni-berlin.de>...
> > (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?"
See the later part of my post. :)
> 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?
Well, I am, but I intended to put a not in front of it! (not (null
(member-if #'cond list))) in effect.
> 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?
In Lisp style- write a function to do it.
More information about the Python-list