Velocity Reviews > RE: if does not evaluate

# RE: if does not evaluate

James Moughan
Guest
Posts: n/a

 06-12-2004
Jacek Generowicz <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> http://www.velocityreviews.com/forums/(E-Mail Removed) (James Moughan) writes:
>
> > Now, how to do this in Lisp. There are several functions for applying
> > a function to the elements of a list to select them, though AFAIK none
> > specifically for our purpose. I may very well be wrong there
> > o'course. One way is:
> >
> > (define has-element (cond list)
> > (equal () (member-if #'cond list))))

>
> (some #'cond list)
>

Fair-nuff; I K'ed incorrectly.

> > We have to have a rather arbitrary #' funcall and syntax to stop a
> > function evaluating long enough to shift it to where it's useful.

>
> What on earth are you talking about ?

Quoting #' a function.

James Moughan
Guest
Posts: n/a

 06-12-2004
Jim Newton <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> > (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.

>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?
>

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?
>
> -jim

In Lisp style- write a function to do it.

Guest
Posts: n/a

 06-16-2004
And with list comprehension
if [x for x in Liste if x=="Red"]

"Nicolas Fleury" <(E-Mail Removed)_remove_the_> a écrit dans le message
news: fXqxc.31545\$(E-Mail Removed)...
> Robert Brewer wrote:
> > If your main desire is to code in some other language while still using
> > Python, write your own VB-style IIf function:

>
> All the solutions you propose don't work (except the long form). You
> cannot code an "iif" function. Test:
>
> def iif(cond, expr1, expr2):
> if cond: return expr1
> return expr2
> def foo(x): return iif(x == 0, 0, 1.0/x)
> foo(4)
> foo(0)
>
> See PEP 308.
>
> Regards,
> Nicolas

Jacek Generowicz
Guest
Posts: n/a

 06-17-2004
[This got lost in a daemon problem at my end ... here it goes again.]

(E-Mail Removed) (James Moughan) writes:

> > > We have to have a rather arbitrary #' funcall and syntax to stop a
> > > function evaluating long enough to shift it to where it's useful.

> >
> > What on earth are you talking about ?

>
> Quoting #' a function.

This is not about delaying evaluation.

#' is a reader macro for FUNCTION:

#'foo => (function foo)

Common Lisp is what is known as a Lisp-2: this means that it has
separate namespaces for variables and functions (actually, it's more
like a Lisp-7, or a Lisp-at-least-7). #' is used in situations where
you need to specify explicitly that the namespace you are referring to
is the function namespace.

I'm not going to discuss, here, whether a single namespace is better
or worse than a multiple one (the Lisp-1 vs Lisp-2 debate/religious
war/flamefest); Google c.l.lisp or c.l.scheme if you feel like it (I

Anyway, the point is that #' has nothing to do with "stop[ping] a
function evaluating"