Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Securing a future for anonymous functions in Python

Reply
Thread Tools

Securing a future for anonymous functions in Python

 
 
Jeff Shannon
Guest
Posts: n/a
 
      01-11-2005
Jacek Generowicz wrote:

> Given a population with previous exposure to computer programming, my
> money is on the map-lambda version. But this last point is mostly
> irrelevant. The fact is that you cannot program computers without
> doing a bit of learning ... and the lambda, map and friends really do
> not take any significant learning.


I guess we'll have to agree to disagree, because given the same
conditions, I *still* think that a list comprehension expresses its
semantics more clearly than map/lambda. I'd also point out that not
all Python programmers will have significant prior exposure to
programming ideas, and even those who do will not necessarily have
prior exposure to lambdas.

It's true that programming requires learning, and that map/lambda
aren't a tremendous burden to learn. Still, to my mind they make a
program a tiny increment more complicated. (I find that reading a
lambda requires mentally pushing a stack frame to parse the lambda and
another to translate map() into a loop, whereas a list comp's
expression doesn't require such a shift, and a function name works as
a good placeholder that makes reading easier.) It's not a big
difference in any individual case, but incremental differences build up.

From the sounds of it, you may have the opposite experience with
reading map/lambda vs. reading list comps, though, so we could go back
and forth on this all week without convincing the other.

>>Speaking for *this* laboratory rat, at least, map/lambda was always a
>>nasty puzzle for me and difficult to sort out. But when list comps
>>were introduced, after reading just a sentence or two on how they
>>worked, they were completely clear and understandable -- much more so
>>than map/lambda after many months of exposure.

>
> Forgetting about lambda, map, filter and reduce, do you find that you
> pass callables around in your Python programs, or is this not
> typically done in your programs?


Sure, I pass callables around quite a bit. Usually they're GUI
callbacks or the like. Usually they're also either complex enough
that lambda would be undesireable if not impossible, or they're simple
and numerous (e.g. calling a function with different parameters) such
that it's easy to write a factory function that returns closures
rather than feed the parameter in with a lambda.

Jeff Shannon
Technician/Programmer
Credit International

 
Reply With Quote
 
 
 
 
Donn Cave
Guest
Posts: n/a
 
      01-11-2005
In article <(E-Mail Removed)>,
Jeff Shannon <(E-Mail Removed)> wrote:
....
> From the sounds of it, you may have the opposite experience with
> reading map/lambda vs. reading list comps, though, so we could go back
> and forth on this all week without convincing the other.


I'm with him. List incomprehensions do not parse well in
my eyes. I am reduced to guessing what they mean by a kind
of process of elimination. map is simply a function, so
it doesn't pose any extra reading problem, and while lambda
is awkward it isn't syntactically all that novel.

Donn Cave, http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Jacek Generowicz
Guest
Posts: n/a
 
      01-12-2005
Jeff Shannon <(E-Mail Removed)> writes:

> I guess we'll have to agree to disagree


Indeed

> I find that reading a lambda requires mentally pushing a stack frame
> to parse the lambda and another to translate map() into a loop,
> whereas a list comp's expression doesn't require such a shift


> From the sounds of it, you may have the opposite experience with
> reading map/lambda vs. reading list comps


No, I'm perefectly happy with both. I'm just trying to understand the
underlying reasons for people having trouble with one or the other, in
order to be better armed when the didactic need might arise.

One more question. Imagine that Python had something akin to Smalltalk
code blocks. Would something like

map([x | x+1], seq)

be any better for you than

map(lambda x+1, seq)

?
 
Reply With Quote
 
Jacek Generowicz
Guest
Posts: n/a
 
      01-12-2005
Donn Cave <(E-Mail Removed)> writes:

> List incomprehensions do not parse well in my eyes.


Are you familiar with the Haskell syntax for list comprehensions?

For example:

http://www.zvon.org/other/haskell/Ou...reference.html

Does their striking similarity to mathematical set notation help at
all ?
 
Reply With Quote
 
Donn Cave
Guest
Posts: n/a
 
      01-12-2005
In article <(E-Mail Removed)>,
Jacek Generowicz <(E-Mail Removed)> wrote:
> Donn Cave <(E-Mail Removed)> writes:
>
> > List incomprehensions do not parse well in my eyes.

>
> Are you familiar with the Haskell syntax for list comprehensions?
>
> For example:
>
> http://www.zvon.org/other/haskell/Ou...on_reference.h


I haven't used it more than once or twice in the modest
amount of Haskell code I've written, but I've seen it
a few times.

> Does their striking similarity to mathematical set notation help at
> all ?


Not a bit.

If it's any more obvious than the Python version, I suppose
it's the | -- my parser sees [a|b] on the first pass.

But it isn't like I ever made any real effort to get comfortable
with Python list comprehensions. I was just relaying my (lack of)
intuitive grasp of them, compared to map and lambda.

Donn Cave, (E-Mail Removed)
 
Reply With Quote
 
Jeff Shannon
Guest
Posts: n/a
 
      01-12-2005
Jacek Generowicz wrote:

> One more question. Imagine that Python had something akin to Smalltalk
> code blocks. Would something like
>
> map([x | x+1], seq)
>
> be any better for you than
>
> map(lambda x+1, seq)
>
> ?


I'd say that this is very slightly better, but it's much closer (in my
mind) to map/lambda than it is to a list comprehension. In this case,
at least the code block is visually self-contained in a way that
lambdas are not, but I still have to do more mental work to visualize
the overall results than I need with list comps.

Jeff Shannon
Technician/Programmer
Credit International

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Would Anonymous Functions Help in Learning Programming/Python? Cristian Python 66 09-24-2007 03:26 PM
Is this a local anonymous class or a member anonymous class Reporter Java 3 05-12-2007 05:23 AM
help with an anonymous array of anonymous hashes noeldamonmiller@gmail.com Perl Misc 1 02-10-2005 01:08 AM
Re: Securing a future for anonymous functions in Python Jp Calderone Python 8 01-01-2005 12:00 AM
please help me in distinguish redefining functions, overloading functions and overriding functions. Xiangliang Meng C++ 1 06-21-2004 03:11 AM



Advertisments