List comprehension confusion...

Lulu of the Lotus-Eaters mertz at gnosis.cx
Mon Feb 10 11:08:51 EST 2003


It's funny the number of things Kylheku got just plain factually wrong,
in the middle of all the invectives he advanced my way.  I suppose I
should forget it, since it is a few days later that I see it anyway.
But there are a couple moderately interesting mathematical points to
mention for other discussants:

kaz at ashi.footprints.net (Kaz Kylheku) wrote previously:
|Doh, haven't you ever heard of lambda calculus? Where do you think the
|term ``lambda'' comes from? It's the greek letter used in the notation

Yeah... that's why I said as much in the same thread.

|In a real programming language, an anonymous function has the full
|power of an ordinary named function.

Well... of course languages like Python, Perl, Java, C, C++, Fortran,
TCL, Ruby, C#, Objective C, BCPL, xBase, COBOL, and even VB -are- Turing
Complete.  I think the idea here is supposed to be "real==Lisp"... which
feels a bit limiting.

|Your arguments about purity are ill-conceived; you are arguing that
|some kind of semantic purity is supported by the impurity of an
|idiotic syntax which prevents you from having the same expressivity in
|a lambda as in a regular function.

I'm not sure what syntax I am defending.  After all, I wrote that I
liked the Haskell syntax better than Python's.  Is the idea that Haskell
has idiotic syntax? Who knows?

But readers might want to be aware that a "pure function" has a specific
meaning.  Namely, it is a function that maps a domain to a range in a
context independent way.  I.e. it does not depend on *state* to perform
an algorithmic calculation; e.g. no global variables, no mutable
instance members, etc.  Haskell functions are pure, those in most
languages are not generally so... but you can decide to write pure
functions in other languages (like Python) if you want.  That was the
point of my idea that it was good to use the lambda style as a hint that
you are writing a pure functions, rather than one that depends on
external state.

A pure function has nothing to do with a "good" function versus a "bad"
function (nor a good language versus bad language).  Or it only does if
you are some sort of ultra-orthodox FP purist; I am certainly not such.
There *are* reasons why you might prefer to write a pure function in
some particular contexts, but that's a best practices matters, not a
moral imperative.

It might also be worth understanding what a FUNCTION really is (I don't
think Kylheku does, despite the bit about the lambda calculus).  A
function, in mathematics, is simply a mapping from a domain to a range.
Or a set of ordered pairs from the Cartesian produce (D X R), where each
first element occurs at most once.  The point with my
dictionary/function examples was just to illustrate this abstract
meaning (both were functions in the mathematical sense, the one a
subfunction of the other).

In general, any time you write a (pure) function in a programming
languages, you are just using a convenient notion to express a
mathematical relation.  It's a lot handier than explicitly listing every
integer, for example, but all it really does is define a pair for every
domain element.

|simply a braindamaged limitation, and one that doesn't exist in some
|other languages that have lexical closures.

I don't know what this is supposed to be about.  Python has closures, of
course.

Yours, Lulu...

--
mertz@  | The specter of free information is haunting the `Net!  All the
gnosis  | powers of IP- and crypto-tyranny have entered into an unholy
.cx     | alliance...ideas have nothing to lose but their chains.  Unite
        | against "intellectual property" and anti-privacy regimes!
-------------------------------------------------------------------------






More information about the Python-list mailing list