[Python-Dev] Partial function application (original) (raw)
Brett Cannon brett at python.org
Fri Sep 11 19:52:07 CEST 2015
- Previous message (by thread): [Python-Dev] Partial function application
- Next message (by thread): [Python-Dev] Partial function application
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, 11 Sep 2015 at 10:41 Herbert Kruitbosch < python-dev at herbertkruitbosch.com> wrote:
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: datasorted = sort(data, key = lambda x: x[0])
To start off, I wouldn't write it that way, but this way:
data_sorted - sort(data, key=operator.itemgetter(0))
where I would prefer datasorted = sort(data, key = #1[0])
That syntax won't work because #
is used to start a comment and there is
no way to disambiguate that in the grammar.
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.
In my code the few times I want partial function applications I have found the functions in the operator module meet that need, else functools.partial or a quickly written closure do the trick. I don't think dedicated syntax is warranted when those other options already exist to meet the same need.
Yours sincerely and thank you in advance,
Thanks for the suggestion!
-Brett
Herbert
Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/brett%40python.org -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20150911/c57111a4/attachment.html>
- Previous message (by thread): [Python-Dev] Partial function application
- Next message (by thread): [Python-Dev] Partial function application
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]