473,382 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

PEP 309 (Partial Function Application) Idea

Random idea of the day: How about having syntax support for
currying/partial function application, like this:

func(..., a, b)
func(a, ..., b)
func(a, b, ...)

That is:
1) Make an Ellipsis literal legal syntax in an argument list.
2) Have the compiler recognize the Ellipsis literal and transform the
function call into a curried/parially applied function.

So the compiler would essentially do something like this:

func(a, ...) ==> curry(func, a)
func(..., a) ==> rightcurry(func, a)
func(a, ..., b) ==> rightcurry(curry(func,a), b)

I haven't though this through much, and I'm sure there are issues, but
I do like the way it looks. The "..." really stands out as saying
"something is omitted here".
Chris Perkins
Jul 18 '05 #1
3 1786
Chris Perkins wrote:
Random idea of the day: How about having syntax support for
currying/partial function application, like this:

func(..., a, b)
func(a, ..., b)
func(a, b, ...)

That is:
1) Make an Ellipsis literal legal syntax in an argument list.
2) Have the compiler recognize the Ellipsis literal and transform the
function call into a curried/parially applied function.

So the compiler would essentially do something like this:

func(a, ...) ==> curry(func, a)
func(..., a) ==> rightcurry(func, a)
func(a, ..., b) ==> rightcurry(curry(func,a), b)

I haven't though this through much, and I'm sure there are issues, but
I do like the way it looks. The "..." really stands out as saying
"something is omitted here".


Interesting idea, but I have a feeling that it probably won't fly for a
couple of reasons:

(1) The existing use of Ellipsis doesn't have anything to do with your
suggested use. I think people are generally opposed to giving
keywords/symbols in Python two very different meanings. This is one of
the reasons Guido never liked the "a, b, *c = iterable" syntax.

(2) Emphasis recently on python-dev has been away from syntax changes
and towards expansion of the standard library. You would have to make a
_very_ good case that the new syntax is merited.

Generally I do like the idea -- I think a lot of the cases that people
have made for keeping lambda could be discarded with something like
this... But it'd need an extremely well thought out PEP (and an
implementation of course) and even then, I wouldn't get my hopes up.

STeVe
Jul 18 '05 #2
Steven Bethard wrote:
Chris Perkins wrote:
Random idea of the day: How about having syntax support for
currying/partial function application, like this:

func(..., a, b)
func(a, ..., b)
func(a, b, ...)

That is:
1) Make an Ellipsis literal legal syntax in an argument list.
2) Have the compiler recognize the Ellipsis literal and transform the
function call into a curried/parially applied function.

So the compiler would essentially do something like this:

func(a, ...) ==> curry(func, a)
func(..., a) ==> rightcurry(func, a)
func(a, ..., b) ==> rightcurry(curry(func,a), b)

I haven't though this through much, and I'm sure there are issues, but
I do like the way it looks. The "..." really stands out as saying
"something is omitted here".


Interesting idea, but I have a feeling that it probably won't fly for a
couple of reasons:

(1) The existing use of Ellipsis doesn't have anything to do with your
suggested use. I think people are generally opposed to giving
keywords/symbols in Python two very different meanings. This is one of
the reasons Guido never liked the "a, b, *c = iterable" syntax.

(2) Emphasis recently on python-dev has been away from syntax changes
and towards expansion of the standard library. You would have to make a
_very_ good case that the new syntax is merited.

Generally I do like the idea -- I think a lot of the cases that people
have made for keeping lambda could be discarded with something like
this... But it'd need an extremely well thought out PEP (and an
implementation of course) and even then, I wouldn't get my hopes up.


I like it, and if it helps to convince people that it is okay to get rid
of lambda, perhaps Guido will like it too.

What about proposing it on python-dev?

Reinhold
Jul 18 '05 #3
Reinhold Birkenfeld wrote:
Steven Bethard wrote:
Chris Perkins wrote:
Random idea of the day: How about having syntax support for
currying/partial function application, like this:
func(..., a, b)
func(a, ..., b)
func(a, b, ...)

That is:
1) Make an Ellipsis literal legal syntax in an argument list.
2) Have the compiler recognize the Ellipsis literal and transform
the function call into a curried/parially applied function.
So the compiler would essentially do something like this:

func(a, ...) ==> curry(func, a)
func(..., a) ==> rightcurry(func, a)
func(a, ..., b) ==> rightcurry(curry(func,a), b)

I haven't though this through much, and I'm sure there are issues, but
I do like the way it looks. The "..." really stands out as saying
"something is omitted here".


The interaction of this with keyword args and omitted args is
problematic (as is the case for rightcurry, in fact). I can't
think of a good way to explain what _should_ happen for a
function defined as def function(*args, **kwargs): ... when you:

def fun(bug, frog, verb): ...
f1 = function(1, ..., frog=3)
f2 = f1(..., 4)
f2()

Keywords were why I did no rightcurry definition in the first place;
I couldn't convince myself there was a good, obvious, resolution.

--Scott David Daniels
Sc***********@Acm.Org
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Paul MG | last post by:
Hi Template partial specialization always seems like a fairly straightforward concept - until I try to do it :). I am trying to implement the input sequence type (from Stroustrup section...
43
by: nospam | last post by:
I got three (3) files (1) Untitled.aspx (2) Untitled.aspx.1.cs (3) Untitled.aspx.2.cs These three files must be used together to make file #1, Untitled.aspx, page work via J.I.T. when the...
7
by: Lionel B | last post by:
Greetings. The following code compiles ok and does what I'd expect it to do: ---------- START CODE ---------- // test.cpp
7
by: Lasse Vågsæther Karlsen | last post by:
I have a list of items and a "rule" for ordering them. Unfortunately, the rule is not complete so it won't define the correct order for any two items in that list. In other words, if I pick...
2
by: Larry | last post by:
I have the following code attached to a search button on a form that runs a query. It works great, except that the search for Last Name only returns exact matches. It is even case sensitive....
6
by: Ronald Mai | last post by:
In my opinion, Ellipsis might be in the middle, not only in leftmost or rightmost, so a placeholder approach can be much more flexible and convenient. Here is a reference implementation: _ =...
1
by: vectorizor | last post by:
Hello, I've got a template function: template <typename U, typename T> void func(ColourImage<U&input,GrayImage<T&out_r, GrayImage<T> &out_g, GrayImage<T&out_b); and I would like to...
1
by: hardieca | last post by:
Hi! I decorate my unfinished classes and methods with a custom TODO attribute (as in things To Do). Using reflection, I am then able to parse through my classes and output all TODOs to a list I...
5
by: Matthew Wilson | last post by:
I wrote some code to create a user and update a user on a remote box by sending emails to that remote box. When I was done, I realized that my create_user function and my update_user function were...
5
by: SAL | last post by:
Hello, I would like to be able to set the WHERE clause of a select statement on the fly. I have a DataAccess layer designed using the DataSet designer and a BusinessLogic layer using classes. The...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.