# Would Anonymous Functions Help in Learning Programming/Python?

Sun Sep 23 10:13:11 CEST 2007

```
Scott David Daniels wrote:
>>
>> Scott David Daniels wrote:
>>> Cristian wrote:
>>>> On Sep 21, 3:44 pm, Ron Adam <r... at ronadam.com> wrote:
>>>>
>>>>> I think key may be to discuss names and name binding with your friend.
>>> Here's an idea:
>>>
>>> import math
>>>
>>> def sin_integral(start, finish, dx): ...
>>> def cos_integral(start, finish, dx): ...
>>> generalize and separate the integration technique from the
>>> function it integrates.
>> It's based on the apple basic program example in How to Enjoy Calculus.
>>    Ron
>>
>> import math
>> def integrate(fn, x1, x2, n=100):...
>> def fn(x): ...
>> print "Area of fn:", integrate(fn, 0, 2)
>> print "Area of cos fn:", integrate(math.cos, 1, 2)
>
> The point was a pedagogic suggestion, i.e.

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.

>"Try taking your
> friend along this path."   I wasn't trying to do a particularly
> good job integrating, simply trying to show how you could
> motivate first-class functions by showing a "useful" and
> "fun" (at least to an engineer) function that cries out
> for higher order functions.  In my experience engineers
> often want a "reason its useful" before engaging with an
> idea.  I'll bet that after a few such experiences he'll see
> how passing around functions and (later) making functions from
> from functions is a great tool to have in his toolbox.  Once
> he sees that, there will be no problem.

Yes, I agree. Another useful thing I've found is to store functions in a
dictionary and call them (dispatching) based on some data value.

Ron

```