[Python-ideas] custom predicate for all() & any()

Michael Selik mike at selik.org
Tue Mar 29 13:48:17 EDT 2016


On Tue, Mar 29, 2016 at 9:15 AM Sven R. Kunze <srkunze at mail.de> wrote:

> On 26.03.2016 18:04, Terry Reedy wrote:
> > So proposed all(iterable, predicate) ==  all(map(predicate, iterable))
>
> I am no native English speaker. Is predicate the right word for this?
>

I'm not sure being a native speaker would help in this case. :-)

One reasonably common definition of "predicate": a function that tests a
condition on a value and returns True/False. Some folks define it more
broadly, but then the word loses its usefulness as distinct from other
kinds of functions. The usage of "predicate" here comes from predicate
logic, or more specifically the usage of the term in languages like Lisp.
Where Python says ``'42'.isnumeric()`` a lisper might say ``(numberp 42)``,
the "p" suffix indicating that it's a predicate function.

https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node69.html


> I get the feeling we would rebuilding things over and over again: list
> comprehensions, filter, map, itertools, for-loops etc.
>

Certainly feels like it.


> I think the underlying issue is the number of parentheses involved. I
> myself somehow avoid nesting too many function calls into one line just
> because of that; not because of the complexity involved but because it
> looks strange.


Same here. But I don't mind the occasional throwaway variable. When it's a
multi-step process, a good name for an intermediate stage helps me think.


> Of course the number of parentheses involved is an
> indicator of the complexity. Not sure if there is another way of
> handling this; maybe piping or something. Would be great if we could
> avoid writing ))) or ))))).
>

http://xkcd.com/297/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160329/f7d281c8/attachment.html>


More information about the Python-ideas mailing list