Python syntax in Lisp and Scheme
Marco Antoniotti
marcoxa at cs.nyu.edu
Wed Oct 8 10:58:12 EDT 2003
David Mertz wrote:
> My answer sucked in a couple ways.
>
> (1) As Bengt Ricther pointed out up-thread, I should have changed David
> Eppstein's names 'filter' and 'iter' to something other than the
> built-in names.
>
> (2) The function categorize_compose() IS named correctly, but it doesn't
> DO what I said it would. If you want to fulfill ALL the filters, you
> don't to compose them, but... well, 'all()' them:
>
> | def categorize_jointly(preds, it):
> | results = [[] for _ in len(preds)]
> | for x in it:
> | results[all(filters)(x)].append(x)
> | return results
>
> Now if you wonder what the function 'all()' does, you could download:
>
> http://gnosis.cx/download/gnosis/util/combinators.py
>
> But the relevant part is:
>
> from operator import mul, add, truth
> apply_each = lambda fns, args=[]: map(apply, fns, [args]*len(fns))
> bools = lambda lst: map(truth, lst)
> bool_each = lambda fns, args=[]: bools(apply_each(fns, args))
> conjoin = lambda fns, args=[]: reduce(mul, bool_each(fns, args))
> all = lambda fns: lambda arg, fns=fns: conjoin(fns, (arg,))
>
> For 'lazy_all()', look at the link.
>
> See, Python is Haskell in drag.
Come on. Haskell has a nice type system. Python is an application of
Greespun's Tenth Rule of programming.
Cheers
--
Marco
>
> Yours, David...
>
> --
> Keeping medicines from the bloodstreams of the sick; food from the bellies
> of the hungry; books from the hands of the uneducated; technology from the
> underdeveloped; and putting advocates of freedom in prisons. Intellectual
> property is to the 21st century what the slave trade was to the 16th.
>
More information about the Python-list
mailing list