[Python-ideas] Predicate Sets

Haoyi Li haoyi.sg at gmail.com
Tue Jan 21 02:51:36 CET 2014


> What if you want to filter according to multiple conditions?

What's wrong with

lambda fname: func1(fname) and func2(fname) and func3(fname)

?


On Mon, Jan 20, 2014 at 5:07 PM, Steven D'Aprano <steve at pearwood.info>wrote:

> On Sun, Jan 19, 2014 at 11:56:49PM -0800, Andrew Barnert wrote:
>
> > And your suggestion has the exact same problem that naive set theory had:
>
> > >>> russellset = predicateset(lambda s: s not in s)
> > >>> russellset in russelset
> >
> > Presumably this should cause the computer to scream "DOES NOT
> > COMPUTE!" and blow up, which I think would be hard to implement in
> > CPython.
>
> It should just raise an exception. I leave implementation as an exercise
> for the reader :-)
>
> This sort of thing is a staple of bad old science fiction, where the
> Hero would save the world by getting the super-intelligent Artificial
> Intelligence Doomsday Computer to calculate some variation of the above.
> But of course, a *truely* intelligent computer would merely say "I see
> what you did there. Good try, feeble meatbag, but not good enough" and
> launch the missiles.
>
>
> > The big problem is coming up with a compelling use case. This one
> doesn't sell me:
> >
> >     bar_files = search_files('bar', exclude=predicateset(lambda fname:
> not fname.endswith('~')))
>
> If it's a project on PyPI, the only use-case necessary is the author
> thinks it's cool.
>
>
> > It seems like it make more sense to have exclude take a function, so you
> could just write:
> >
> >     bar_files = search_files('bar', exclude=lambda fname: not
> fname.endswith('~'))
>
> What if you want to filter according to multiple conditions? A tuple of
> functions makes sense. Add a helper function that tests against those
> multiple functions, and you're halfway to this PredicateSet. Adding
> set-like methods seems like overkill.
>
>
> --
> Steven
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140120/abd2c339/attachment.html>


More information about the Python-ideas mailing list