Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #9836 > unrolled thread

Re: Partial Function Application -- Advantages over normal function?

Started byDave Angel <davea@ieee.org>
First post2011-07-18 17:45 -0400
Last post2011-07-19 12:47 -0400
Articles 9 — 5 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Partial Function Application -- Advantages over normal function? Dave Angel <davea@ieee.org> - 2011-07-18 17:45 -0400
    Re: Partial Function Application -- Advantages over normal function? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-07-19 00:28 +0200
      Re: Partial Function Application -- Advantages over normal function? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-07-19 00:33 +0200
        Re: Partial Function Application -- Advantages over normal function? Thomas Jollans <t@jollybox.de> - 2011-07-19 08:22 +0200
        Re: Partial Function Application -- Advantages over normal function? Ian Kelly <ian.g.kelly@gmail.com> - 2011-07-19 10:49 -0600
        Re: Partial Function Application -- Advantages over normal function? Thomas Jollans <t@jollybox.de> - 2011-07-19 18:58 +0200
        Re: Partial Function Application -- Advantages over normal function? Ian Kelly <ian.g.kelly@gmail.com> - 2011-07-19 11:15 -0600
      Re: Re: Partial Function Application -- Advantages over normal function? Dave Angel <davea@ieee.org> - 2011-07-19 06:07 -0400
      Re: Partial Function Application -- Advantages over normal function? Terry Reedy <tjreedy@udel.edu> - 2011-07-19 12:47 -0400

#9836 — Re: Partial Function Application -- Advantages over normal function?

FromDave Angel <davea@ieee.org>
Date2011-07-18 17:45 -0400
SubjectRe: Partial Function Application -- Advantages over normal function?
Message-ID<mailman.1232.1311025576.1164.python-list@python.org>
On 01/-10/-28163 02:59 PM, Terry Reedy wrote:
> On 7/18/2011 8:24 AM, Paul Woolcock wrote:
>> Partial function application (or "currying") is the act of taking a
>> function with two or more parameters, and applying some of the arguments
>> in order to make a new function.  The "hello world" example for this
>> seems to be this:
>> <snip>
>
> def makeadder(y)
>     def _add(x): return x+y
> add2 = makeadder(2)
>
> <snip>

A couple of typos in that code:


def makeaddr(y):
     def _add(x): return x+y
     return _add


DaveA

[toc] | [next] | [standalone]


#9838

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2011-07-19 00:28 +0200
Message-ID<1405042.q1RDiLHYyK@PointedEars.de>
In reply to#9836
Dave Angel wrote:

> On 01/-10/-28163 02:59 PM, Terry Reedy wrote:
>> def makeadder(y)
>>     def _add(x): return x+y
>> add2 = makeadder(2)
> 
> A couple of typos in that code:
> 
> 
> def makeaddr(y):
>      def _add(x): return x+y
>      return _add

I agree about the `return' statement, but not about the factory name; this 
has nothing to do with addresses (addr).

-- 
PointedEars

Bitte keine Kopien per E-Mail. / Please do not Cc: me.

[toc] | [prev] | [next] | [standalone]


#9839

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2011-07-19 00:33 +0200
Message-ID<4247181.bSrEuok8ZT@PointedEars.de>
In reply to#9838
Thomas 'PointedEars' Lahn wrote:

> Dave Angel wrote:
>> On 01/-10/-28163 02:59 PM, Terry Reedy wrote:
>>> def makeadder(y)
>>>     def _add(x): return x+y
>>> add2 = makeadder(2)
>> 
>> A couple of typos in that code:
>> 
>> def makeaddr(y):
>>      def _add(x): return x+y
>>      return _add
> 
> I agree about the `return' statement, but not about the factory name; this
> has nothing to do with addresses (addr).

Supplemental: The above can be simplified to

def makeadder(y): return lambda x: x + y

-- 
PointedEars

Bitte keine Kopien per E-Mail. / Please do not Cc: me.

[toc] | [prev] | [next] | [standalone]


#9858

FromThomas Jollans <t@jollybox.de>
Date2011-07-19 08:22 +0200
Message-ID<mailman.1239.1311056526.1164.python-list@python.org>
In reply to#9839
On 19/07/11 00:33, Thomas 'PointedEars' Lahn wrote:
> Thomas 'PointedEars' Lahn wrote:
> 
>> Dave Angel wrote:
>>> On 01/-10/-28163 02:59 PM, Terry Reedy wrote:
>>>> def makeadder(y)
>>>>     def _add(x): return x+y
>>>> add2 = makeadder(2)
>>>
>>> A couple of typos in that code:
>>>
>>> def makeaddr(y):
>>>      def _add(x): return x+y
>>>      return _add
>>
>> I agree about the `return' statement, but not about the factory name; this
>> has nothing to do with addresses (addr).
> 
> Supplemental: The above can be simplified to
> 
> def makeadder(y): return lambda x: x + y
> 

In turn:

makeadder = lambda y: lambda x: x + y

Smells of Haskell.

[toc] | [prev] | [next] | [standalone]


#9889

FromIan Kelly <ian.g.kelly@gmail.com>
Date2011-07-19 10:49 -0600
Message-ID<mailman.1258.1311094174.1164.python-list@python.org>
In reply to#9839
On Tue, Jul 19, 2011 at 12:22 AM, Thomas Jollans <t@jollybox.de> wrote:
>> Supplemental: The above can be simplified to
>>
>> def makeadder(y): return lambda x: x + y
>>
>
> In turn:
>
> makeadder = lambda y: lambda x: x + y

That's not an improvement.  lambda is for making anonymous functions.
If you're going to construct a lambda and bind it to a name, you
should just use def.

[toc] | [prev] | [next] | [standalone]


#9890

FromThomas Jollans <t@jollybox.de>
Date2011-07-19 18:58 +0200
Message-ID<mailman.1260.1311094712.1164.python-list@python.org>
In reply to#9839
On 19/07/11 18:49, Ian Kelly wrote:
> On Tue, Jul 19, 2011 at 12:22 AM, Thomas Jollans <t@jollybox.de> wrote:
>>> Supplemental: The above can be simplified to
>>>
>>> def makeadder(y): return lambda x: x + y
>>>
>>
>> In turn:
>>
>> makeadder = lambda y: lambda x: x + y
> 
> That's not an improvement.  lambda is for making anonymous functions.
> If you're going to construct a lambda and bind it to a name, you
> should just use def.

No, it's not an improvement. It's an illustration.

[toc] | [prev] | [next] | [standalone]


#9896

FromIan Kelly <ian.g.kelly@gmail.com>
Date2011-07-19 11:15 -0600
Message-ID<mailman.1262.1311095754.1164.python-list@python.org>
In reply to#9839
On Tue, Jul 19, 2011 at 10:58 AM, Thomas Jollans <t@jollybox.de> wrote:
> No, it's not an improvement. It's an illustration.

I get that.  The difference I pointed out between your
"simplification" and the other Thomas's is the reason why yours would
be unpythonic whilst his is fine.

[toc] | [prev] | [next] | [standalone]


#9870

FromDave Angel <davea@ieee.org>
Date2011-07-19 06:07 -0400
Message-ID<mailman.1246.1311070085.1164.python-list@python.org>
In reply to#9838
On 01/-10/-28163 02:59 PM, Thomas 'PointedEars' Lahn wrote:
> Dave Angel wrote:
>
>> On 01/-10/-28163 02:59 PM, Terry Reedy wrote:
>>> def makeadder(y)
>>>      def _add(x): return x+y
>>> add2 = makeadder(2)
>> A couple of typos in that code:
>>
>>
>> def makeaddr(y):
>>       def _add(x): return x+y
>>       return _add
> I agree about the `return' statement, but not about the factory name; this
> has nothing to do with addresses (addr).
>

The two changes that I made deliberately were adding the colon and 
adding the return statement.  I'm not sure how the name got changed;  
that was accidental.

DaveA

[toc] | [prev] | [next] | [standalone]


#9888

FromTerry Reedy <tjreedy@udel.edu>
Date2011-07-19 12:47 -0400
Message-ID<mailman.1259.1311094202.1164.python-list@python.org>
In reply to#9838
On 7/19/2011 6:07 AM, Dave Angel wrote:
> On 01/-10/-28163 02:59 PM, Thomas 'PointedEars' Lahn wrote:
>> Dave Angel wrote:
>>
>>> On 01/-10/-28163 02:59 PM, Terry Reedy wrote:
>>>> def makeadder(y)
>>>> def _add(x): return x+y
>>>> add2 = makeadder(2)
>>> A couple of typos in that code:
>>>
>>>
>>> def makeaddr(y):
>>> def _add(x): return x+y
>>> return _add
>> I agree about the `return' statement, but not about the factory name;
>> this
>> has nothing to do with addresses (addr).
>>
>
> The two changes that I made deliberately were adding the colon and
> adding the return statement. I'm not sure how the name got changed; that
> was accidental.

Anyway, my apologies for posting quickly without testing and without 
saying so. I know better and too often leave in mistakes when I do.

-- 
Terry Jan Reedy

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web