[Python-Dev] Partial function application

Herbert Kruitbosch python-dev at herbertkruitbosch.com
Fri Sep 11 09:56:33 CEST 2015


Dear developers,

First of all, I'm a programmer for a data science company and I recently
graduated.

That being said, I have wondered why python does not have syntactical
support (like syntax sugar) for partial function application. I think
partial function application is a powerful concept, but also think that
the implementation in functional.partial as described here:

https://www.python.org/dev/peps/pep-0309/

is too verbose. Moreover I think the functional programming paradigm is
a powerful one in general, especially when implemented as much as
possible in an iterative language as python avoiding the typical
problems we have with purely functional languages like Haskell. An plea
for this concept is that, for example, small pieces Haskell (or
functional) code can be extremely expressive and concise.

I was wondering if there are considerations for including partial
function application syntactically. I very often find myself writing
statements as:

data_sorted = sort(data, key = lambda x: x[0])

where I would prefer

data_sorted = sort(data, key = #1[0])

where the #1 is similar to the one used in Mathematica for the same
purpose. That is, an expression with #1  becomes an anonymous function
which takes one argument, and, obviously, if a #n is included, the
anonymous function takes n arguments.

Notice that #1[0] does not seem like partial function application,
however it is if you (C++'isly) assume that the deference operation []
is a function dereference(subscriptable, subscript).

Obviously, I am only expecting that you get these type of suggestions
all the time and that there is a good change you do not find it adequate
for many reasons, for example keeping the language compact. I this case,
I would also like to hear so.

Yours sincerely and thank you in advance, Herbert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20150911/4341f242/attachment.html>


More information about the Python-Dev mailing list