[Python-Dev] Partial function application 'from the right'

Alexander Belopolsky alexander.belopolsky at gmail.com
Thu Jan 29 22:44:09 CET 2009


This discussion probably belongs to python-ideas, but since we already
have this thread, I'll reply here instead of opening a new thread
there.

Ellipsis was introduced into python to serve needs of the numeric
python community.  If you think of numpy multiarrays as functions
taking ndim number of arguments, then ellipsis is used to denote any
number of missing arguments and : is used to denote a single missing
argument.

By this analogy, partial(f, ..., *args) is right_partial with '...'
standing for any number of missing arguments.  I you want to specify
exactly one missing argument, you would want to write partial(f, :,
*args), which is not a valid syntax even in Py3.

If one is willing to use [] instead of () with partial, it is possible
to implement  partial[f, ..., *args] and partial[f, x, :, z] already
in Py2, but I would rather see : allowed in the argument lists or some
other short syntax for missing arguments.  If such syntax is
introduced, the need for partial may even go away with
partial(str.split, :, ',') spelled simply as str.split(:, ',').

On Thu, Jan 29, 2009 at 3:04 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> Scott David Daniels <Scott.Daniels <at> Acm.Org> writes:
>>
>> Antoine Pitrou wrote:
>> > ...
>> > In py3k, we could also use "..." (the Ellipsis object) to denote
>> > places where an argument is missing, so that:
>> >     split_comma = partial(str.split, ..., ',')
>> > would do what you want.
>>
>> Thus preventing any use of partial when an argument could be an
>> the Ellipsis instance.
>
> Obviously, it is the drawback :) But Ellipsis is hardly used anywhere, and it
> reads good in this very use case.
>
>
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/alexander.belopolsky%40gmail.com
>


More information about the Python-Dev mailing list