[Python-Dev] Partial function application 'from the right'
Collin Winter
collinw at gmail.com
Tue Feb 3 19:11:47 CET 2009
On Tue, Feb 3, 2009 at 5:44 AM, Ben North <ben at redfrontdoor.org> wrote:
> Hi,
>
> Thanks for the further responses. Again, I'll try to summarise:
>
> Scott David Daniels pointed out an awkward interaction when chaining
> partial applications, such that it could become very unclear what was
> going to happen when the final function is called:
>
>> If you have:
>> def button(root, position, action=None, text='*', color=None):
>> ...
>> ...
>> blue_button = partial(button, my_root, color=(0,0,1))
>>
>> Should partial_right(blue_button, 'red') change the color or the text?
>
> Calvin Spealman mentioned a previous patch of his which took the 'hole'
> approach, i.e.:
>
>> [...] my partial.skip patch, which allows the following usage:
>>
>> split_one = partial(str.split, partial.skip, 1)
>
> This would solve my original problems, and, continuing Scott's example,
>
> def on_clicked(...): ...
>
> _ = partial.skip
> clickable_blue_button = partial(blue_button, _, on_clicked)
>
> has a clear enough meaning I think:
>
> clickable_blue_button('top-left corner')
> = blue_button('top-left corner', on_clicked)
> = button(my_root, 'top-left corner', on_clicked, color=(0,0,1))
>
> Calvin's idea/patch sounds good to me, then. Others also liked it.
> Could it be re-considered, instead of the partial_right idea?
Have any of the original objections to Calvin's patch
(http://bugs.python.org/issue1706256) been addressed? If not, I don't
see anything in these threads that justify resurrecting it.
I still haven't seen any real code presented that would benefit from
partial.skip or partial_right.
Collin Winter
More information about the Python-Dev
mailing list