[Python-ideas] Syntax for defining parametric decorators
Mike Meyer
mwm at mired.org
Mon Jul 9 11:56:55 CEST 2012
On Mon, 09 Jul 2012 11:47:48 +0200
Stefan Behnel <stefan_ml at behnel.de> wrote:
> Mike Graham, 08.07.2012 22:22:
> > def timesn(n)(f):
> > def inner(y):
> > return n * f(y)
> > return inner
> >
> > which is more concise and looks a lot more like a non-parametric
> > decorator someone might have written already. The syntax is mostly
> > self-explaining and could potentially be useful in other contexts.
>
> >From an innocent look, I have no idea what the syntax is supposed to mean.
> Clearly doesn't hint at a factory for me.
Does to me. timesn is clearly a function of one argument that is going
to return a callable object that takes one argument. So:
x5 = times(5)
print x5(7)
should print 35.
I'd be interested in seeing an implementation of partial that used
this mechanism. Should be straightforward, but I'm in the midst of a
crunch.
<mike
--
Mike Meyer <mwm at mired.org> http://www.mired.org/
Independent Software developer/SCM consultant, email for more information.
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
More information about the Python-ideas
mailing list