# [Edu-sig] RE: Integration correction

Kirby Urner urnerk at qwest.net
Wed Mar 30 01:19:51 CEST 2005

```> From: Kirby Urner <urnerk at qwest.net>
> > @simpson
> > def g(x):  return x*x
> >
> > >>> g(0, 3)
> > 9.0000000000000036
>
> My resistance to decorators is not unrelated to the fact that I don't seem
> capable of getting my mind around them.
>

Hi Art --

Actually, I'm with you.  The above use is maybe more an example of how *not*
to use them.  I mean, the function g has a perfect right to exist with its
own name, but here gets rebound to another function with its own arguments.

The original g is gone, unless we kept a copy.

The syntax is equivalent too:

g = simpson(g)

nothing more.  But then simpson, which consumes g, also spits back defint
(i.e. is a factory for producing functions), which defint here gets rebound
to g, committing g to oblivion.

Again, I think you're probably right, that this particular example is

The main reason Guido wanted them was to put something critical about a
function at the very top, not after a page of code.  But here, my g is a one
liner.  It makes more sense to just write:

def g(x):  return x*x
intg = simpson(g)
dg   = derivative(g)

That'd keep g around, and give us these new other functions to play with too
(I *do* think that taking a function as an argument and spitting one back
*is* "the right thing" to do in this context i.e. is mathematically on
target -- but decorators?... no, probably not).

Now, if g(x) really *did* go on for 30-40 lines, OK, then maybe a decorator