map/filter/reduce/lambda opinions and background unscientificmini-survey

Chris Rebert (cybercobra) cvrebert at gmail.com
Thu Jul 7 06:34:16 EDT 2005


Agreed, I dislike map and its ilk as well.
However, they are handy in some cases. I particularly like the way Ruby
deals with this problem. Instead of all these functions, internal
iterators and true anonymous blocks are used.
Case in point:

def gt_than_5(obj):
    return obj > 5
results = filter(gt_than_5, seq)

becomes

results = seq.find_all do |item|
  item > 5
end

This has the advantage of writing less code for the common cases by
having them builtin to the class. Instead of everyone needlessly
recoding these over and over again, they're implemented in one place.
This could be done by defining an abstract class that enumerable
objects inherit from. It's not practical, but I can dream, can't I? ;-)
Also, you don't have to define a separate testing function. Granted, in
this case, the test func is trivial, but when it's non-trivial, you
really notice the advantages.

Ivan Van Laningham wrote:
> Hi All--
>
> Tom Anderson wrote:
> >
> > Comrades,
> >
> > "I expect tons of disagreement in the feedback, all from ex-Lisp-or-Scheme
> > folks. :-)"
> >
> > I disagree strongly with Guido's proposals, and i am not an ex-Lisp,
> > -Scheme or -any-other-functional-language programmer; my only other real
> > language is Java. I wonder if i'm an outlier.
> >
> > So, if you're a pythonista who loves map and lambda, and disagrees with
> > Guido, what's your background? Functional or not?
> >
>
> I'm a pythonista who doesn't love them.  In fact, even though I've done
> more than my fair share of lambda Tkinter programming using lambdas,
> I've never been happy with lambda.  And I've spent months inside of
> Lisp/Emacs Lisp/Scheme, too (I have the world's second largest .emacs
> file [my friend Andy Glew has the largest], even though I can't use it
> on Windows;-).  I find list comprehensions easier to understand than
> map, and small named functions or, better yet, class methods, *tons*
> easier to read/understand than lambda--there are too many restrictions
> you have to remember.
>
> Personally, I find that Lisp & its derivatives put your head in a very
> weird place.  Even weirder than PostScript/Forth/RPN, when you come
> right down to it.
>
> I won't miss them, but since I don't use them now, that doesn't mean a
> whole lot.
>
> Metta,
> Ivan
> ----------------------------------------------
> Ivan Van Laningham
> God N Locomotive Works
> http://www.andi-holmes.com/
> http://www.foretec.com/python/workshops/1998-11/proceedings.html
> Army Signal Corps:  Cu Chi, Class of '70
> Author:  Teach Yourself Python in 24 Hours




More information about the Python-list mailing list