[Python-ideas] Syntax for curried functions

Weeble clockworksaint at gmail.com
Mon Mar 2 10:22:10 CET 2009

Would this be crazy? Make this:

def spam(a,b,c)(d,e,f):

a synonym for:

def spam(a,b,c):
    def spam2(d,e,f):
    return spam2

As far as I can tell, it would always be illegal syntax right now, so
it seems a safe change. And it would make it cleaner to write higher
order functions. While I had the idea bouncing round my head, I
realised I would quite like the syntax for writing methods too. E.g.:

class Eggs(object):
    def spam(self)(a,b,c):

Of course, that wouldn't work unless you wrote and used a special
meta-class to change how bound methods work (instead of creating a
bound method with the instance and function, you'd call the "method
function" with the instance and get back the "bound method"), and I
have no idea, but I guess it might slow things down. But I thought it
was worth mentioning because it looked cool.

Anyway, that's tangential to the idea. The idea is that any (positive)
number of parameter lists could follow the method name in its
declaration. The function takes as input its first parameter list and
returns a function that takes the second parameter list, etc., until
there are no more method lists and the last level of function executes
and returns the result of the function body.

More information about the Python-ideas mailing list