Re: foldr function in Python

2007-11-23 Thread MonkeeSage
On Nov 23, 8:56 pm, MonkeeSage <[EMAIL PROTECTED]> wrote: > This doesn't matter for non-associative functions > like "+", but it does for associative functions like "-". Err...that's backwards...should have been: This doesn't matter for associative functions like "+", but it does for non-associa

Re: foldr function in Python

2007-11-23 Thread MonkeeSage
On Nov 23, 7:05 pm, greg <[EMAIL PROTECTED]> wrote: > My feeling is that Python shouldn't provide a bunch of > different versions of the same function that differ only in > the degree of currying. If you want a particular curried > combination, it's easy enough to create it as needed using > lambd

Re: foldr function in Python

2007-11-23 Thread greg
Marc 'BlackJack' Rintsch wrote: > The name is definitely not so good because there is a `foldr` in Haskell > that just works like `reduce()`. Because currying is ubiquitous in Haskell, you can use the same function in either a curried or non-curried fashion. But in Python you need different functi

Re: foldr function in Python

2007-11-23 Thread Steven D'Aprano
On Fri, 23 Nov 2007 15:20:38 +0100, Peter Otten wrote: > reduce() is indeed in the functools -- added by Guido van Rossum > himself. I am extremely glad to be wrong, you've cheered me up no end :-D -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: foldr function in Python

2007-11-23 Thread Peter Otten
Ant wrote: > On Nov 23, 10:54 am, Steven D'Aprano <[EMAIL PROTECTED] > cybersource.com.au> wrote: > ... >> Alas and alack, I believe that Guido has a distaste for all but the >> simplest functional idioms, and an irrational belief that anything using >> reduce() must be too complex to bear. reduce

Re: foldr function in Python

2007-11-23 Thread Ant
On Nov 23, 10:54 am, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: ... > Alas and alack, I believe that Guido has a distaste for all but the > simplest functional idioms, and an irrational belief that anything using > reduce() must be too complex to bear. reduce() is going away, not

Re: foldr function in Python

2007-11-23 Thread Steven D'Aprano
On Fri, 23 Nov 2007 09:31:06 +, Marc 'BlackJack' Rintsch wrote: > Of course it's a silly example because the "pythonic" way to define > `comma_separate()` is:: > > comma_separate = ','.join Except that join only works with strings, and reduce/foldr can work on anything. -- Steven. -- h

Re: foldr function in Python

2007-11-23 Thread Steven D'Aprano
On Fri, 23 Nov 2007 00:50:30 -0800, Ant wrote: > On Nov 22, 7:14 pm, oj <[EMAIL PROTECTED]> wrote: >> On Nov 22, 3:02 pm, Ant <[EMAIL PROTECTED]> wrote: > ... >> It's basically just one line to implement: >> >> foldr = lambda f, i: lambda s: reduce(f, s, i) >> >> It's just reduce with currying, I'

Re: foldr function in Python

2007-11-23 Thread Ant
On Nov 23, 9:31 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Fri, 23 Nov 2007 00:50:30 -0800, Ant wrote: > > So my point really is that foldr (perhaps renamed to make_reducer or > > something) could create idioms that are more readable than using > > reduce directly. > > The name is

Re: foldr function in Python

2007-11-23 Thread Marc 'BlackJack' Rintsch
On Fri, 23 Nov 2007 00:50:30 -0800, Ant wrote: > So my point really is that foldr (perhaps renamed to make_reducer or > something) could create idioms that are more readable than using > reduce directly. The name is definitely not so good because there is a `foldr` in Haskell that just works like

Re: foldr function in Python

2007-11-23 Thread Ant
On Nov 22, 7:14 pm, oj <[EMAIL PROTECTED]> wrote: > On Nov 22, 3:02 pm, Ant <[EMAIL PROTECTED]> wrote: ... > It's basically just one line to implement: > > foldr = lambda f, i: lambda s: reduce(f, s, i) > > It's just reduce with currying, I'm not sure it adds that much to what > python already offe

Re: foldr function in Python

2007-11-22 Thread oj
On Nov 22, 3:02 pm, Ant <[EMAIL PROTECTED]> wrote: > Hi all, > > I've just been reading with interest this > article:http://caos.di.uminho.pt/~ulisses/blog/2007/11/20/foldr-the-magic-fun... > > It's a useful function that (with a more intuitive name) could prove a > compelling addition to the iter

foldr function in Python

2007-11-22 Thread Ant
Hi all, I've just been reading with interest this article: http://caos.di.uminho.pt/~ulisses/blog/2007/11/20/foldr-the-magic-function/ It's a useful function that (with a more intuitive name) could prove a compelling addition to the itertools module. In it's python form, it would be something lik