Newbie: finding the key/index of the min/max element

Alex Martelli aleax at aleax.it
Thu May 2 10:54:01 EDT 2002


On Thursday 02 May 2002 04:36 pm, James J. Besemer wrote:
	...
> > > earlier, when we were talking about map() and filter().
> >
> > Those ARE higher-order functions, you know.
>
> You'll have to define the term for me then.

http://burks.brighton.ac.uk/burks/foldoc/74/52.htm

> (b) perhaps assignment can be eliminated in some kind of "pure" FP (like in
> "pure" Scheme).  BUt in practice programmers need to put the results
> somewhere.   Seems FP could apply to your "overall style" and still use
> assignment.
>
> But you're the expert.

Me?  "I am but an egg".  Still: "assignment" (of the single kind, i.e., no 
RE-binding) is quite compatible with FP; RE-binding and mutation aren't
(if and when you use them, you're thereby "escaping" the paradigm --
just like, e.g., a cut in Prolog takes you out of Logic Programming, a
procedural trigger in your SQL takes you out of Relational Programming,
and so on).  An analogy: if (e.g. in C) *most* of my programming uses
structured control flow via if/while/&c, and "once in a while" I do a goto,
am I doing "structured programming" or not?  It's no doubt a matter of
emphasis -- but surely languages utterly bereft of goto, such as Python,
put you under less temptation.  And, sure, gotoless programming is quite
easy, no matter the fact that "in practice programmers need to have their
control flow go hither and thither".

Similarly for FP -- programming with immutable data and unrebindable
names.  Your data "comes from" somewhere and eventually "goes"
somewhere, but (performance considerations apart) there's no problem
that actually _requires_ you to be able to mutate it or rebind names.

Given that performance considerations cannot necessarily be _kept_
apart, the main worth of FP is still as a thinking tool (in most cases).

Python lets you do a fair amount of FP (including, with creative use of
iterators/generators, the "lazy evaluation" parts of it), but for purely
formative purposes, trying out something really different such as
Haskell (if you're into static typing) or Erlang (if you like dynamic
typing), where you're basically "forced" to follow the paradigm, can be
quite instructive, IMHO.


Alex





More information about the Python-list mailing list