Re: [Python-Dev] Some new additions to functools

2007-04-15 Thread Paul Hankin
On 4/15/07, SevenInchBread [EMAIL PROTECTED] wrote:
 So I've cooked up some very simple functions to add to functools - to expand
 it into a more general-purpose module.

 def cat(x): return x

 class nullfunc(object):
 def __call__(self, *args, **kargs): return self
 def __getattr__(self, name):return getattr(None, name)

 def multimap(func, seq, n=2):
 assert n  0, n must be positive
 if n == 1: return map(func, seq)
 else:   return map(lambda x: multimap(func, x, n-1), seq)

 def multifilter(func, seq, n=2):
 return multimap(lambda x: filter(func, x), seq, n-1)

 def multireduce(func, seq, n=2):
 return multimap(lambda x: reduce(func, x), seq, n-1)

-0 for cat (renamed to 'identity'), -1 for the rest.

I've occasionally wanted multimap but only in the default
case where it is simpler to be explicit.

-- 
Paul Hankin
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] fmod.c

2007-03-10 Thread Paul Hankin
Hi all,

Is there any need for Python/fmod.c any more? I can't see how
it can be included because there's no test for fmod in the
./configure script and grepping all files in the tree for fmod.c
finds nothing except a commented out line in PC/os2vacpp/makefile.omk

If it is needed, it needs fixing as it gives the wrong answer
for x=0 and y0.
Eg:
fmod(0, -1) returns 1 rather than 0.

(The comment in fmod.c is correct: it should return f such that
x = i*y + f for some integer i, st |f|  |y| and f has the same
sign as x).

I'm happy to patch it, but I won't if it would be better just
to remove the file.

-- 
Paul Hankin

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com