Would Anonymous Functions Help in Learning Programming/Python?

Ron Adam rrr at ronadam.com
Mon Sep 24 01:34:20 CEST 2007



Scott David Daniels wrote:
> Ron Adam wrote:
>> Scott David Daniels wrote:
>>> Ron Adam wrote:
>>>> .... How about this?
>>>> def integrate(fn, x1, x2, n=100):...
>>> The point was a pedagogic suggestion, ... 
>> I understood your point.  I just found it interesting since I've been 
>> trying to extend my math (for use with python) skills in this area.
> 
> Ah, sorry.  I had realized I wasn't explicit in my first message.

Yes, I wasn't trying to correct you.  I'm sorry if it came across that way.


> Yes, a perfectly fine integration.

There's still something about it that bothers me.  I think it may be the 
n=100 rather than delta='.0001', or some other way to specify the minimal 
error.  (Yes, it's a bit off topic.)


> You can then (and this is a major jump to get used to):
>      import functools
> 
>      Sine = functools.partial(integrate, math.cos, 0.0, n=100)

I haven't played around with .partial yet.  I wonder if it could be used in 
dispatching situations where the function signatures differ?


> Similarly, you can define a derivative that will behave fairly well,
> all without examining the definition of the function being operated
> upon.

I'll get around to doing that at some point. ;-)


I also have a class that solves equations that takes a function in a 
similar way.  It uses the same method used by HP calculators to solve TVM 
equations.

Cheers,
    Ron





More information about the Python-list mailing list