[Python-ideas] A suggestion for Python 3 vs Python 2
Andrew Barnert
abarnert at yahoo.com
Thu Nov 14 18:58:19 CET 2013
On Nov 14, 2013, at 7:47, אלעזר <elazarg at gmail.com> wrote:
> 2013/11/14 Masklinn <masklinn at masklinn.net>:
>>
>> On 2013-11-14, at 16:05 , Steven D'Aprano <steve at pearwood.info> wrote:
>>> Aside: am I the only one who wishes there was a functools.rpartial, that
>>> binds from the right instead of the left?
>>
>> I’ve wanted this as well. Or the ability to somehow “fill holes”.
>> Scala- or Clojure-type parse transforms are pretty neat for that
>> (write the call with holes/placeholders, the call is deferred as a function
>> taking arguments to fill the placeholders)
>>
>> Examples of Scala have already been provided, in Clojure it’s an explicit
>> reader form:
>>
>> #(foo 1 2 %)
This example doesn't actually show rpartial--but it's enough to make it obvious to anyone how you'd do that in Clojure, so that's ok.
>>
>> is equivalent (and expanded) to
>>
>> (fn [arg] (foo 1 2 arg))
>
> Ellipsis seems suitable for the latter:
>
> sub5 = partial(sub, ..., 5)
>
> (At the expense of giving up the abitily to pass ellipsis to partial functions).
I don't know why, but to me that strongly implies that I'm binding argument -1 (after 0 or more arguments, or maybe 1 or more), rather than argument 2 (after exactly 1).
But that's not necessarily a bad thing. But if other people expect it to bind 2, they'll be surprised when they try it on a 3-argument (or variable-argument) function.
(And yes, I realize that mixing 1-based arg counting with python negative indices is potentially confusing. I don't think it's confusing in this particular case, but in, say, documentation for a stdlib function it could be.)
More information about the Python-ideas
mailing list