Would Anonymous Functions Help in Learning Programming/Python?

Scott David Daniels Scott.Daniels at Acm.Org
Sat Sep 22 16:39:17 CEST 2007


Ron Adam 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.
> 
> How about this?
> 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. "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.

-Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list