[Python-ideas] Syntax for defining parametric decorators

Devin Jeanpierre jeanpierreda at gmail.com
Mon Jul 9 03:45:11 CEST 2012


On Sun, Jul 8, 2012 at 8:52 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> Concise, yes, but I disagree that it is self-explaining.

I think the idea is that just as

  def foo(a): ...

can be called as foo(x) to execute the body,

  def foo(a)(b): ...

can be called as foo(x)(y) to execute the body.

> I'm having a lot of difficulty in thinking of how I would explain it to even
> a moderately experienced user except by expanding it out to the explicit
> nested function form. I'm not sure I can even explain it to myself.

What's wrong with explaining it by expansion?

Also, I doubt it's as hard as you claim. Something similar -- curried
functions -- have been a staple of functional programming languages
since before Python ever existed. This should also help explain it to
lots of new users with wider backgrounds.

> What will happen when the user invariably writes something like this?
>
> def ordinary(a)(b):
>     return a + b

Surely it'd define a curried function s.t. ordinary(1)(2) == 3?

-- Devin



More information about the Python-ideas mailing list