Lambda the Ultimate

inactiveTopic PyCon 2003 Papers
started 4/14/2003; 7:10:49 AM - last post 4/20/2003; 1:53:59 AM
andrew cooke - PyCon 2003 Papers  blueArrow
4/14/2003; 7:10:49 AM (reads: 2391, responses: 7)
PyCon 2003 Papers
Mainly straight Python and incomplete, but some contributions possibly of more general interest, including .net for Python and Traits (strongly typed object attributes).

And, oh look, Paul Graham gave a keynote speech...


Posted to Python by andrew cooke on 4/14/03; 7:13:30 AM

andrew cooke - Re: PyCon 2003 Papers  blueArrow
4/14/2003; 7:15:43 AM (reads: 925, responses: 0)
[Aside: Anyone here uses Privoxy? If so, do you know how I configure it so that I can edit posts here?]

Noel Welsh - Re: PyCon 2003 Papers  blueArrow
4/19/2003; 12:21:27 AM (reads: 702, responses: 2)

Interesting is this slide from Guido's "Python Regret's" talk:

Lambda and functional stuff

I've never liked lambda

  • crippled (only one expression)
  • confusing (no argument list parentheses)
  • can use a local function instead

map(), filter()

  • using a python function here is slow
  • list comprehensions do the same thing better

reduce()

  • nobody uses it, few understand it
  • a for loop is clearer & (usually faster)

The slides don't give much context but it appears Guido is more in favour of removing functional features than improving them (his gripes about lambda are 2/3 syntactical - who controls the syntax Guido?) Is Python really multi-paradigm? The same attitude is expressed in the this ll1-discuss thread. I don't like this attitude that I should be told what style to program in.

andrew cooke - Re: PyCon 2003 Papers  blueArrow
4/19/2003; 5:31:58 AM (reads: 751, responses: 1)
I don't like this attitude that I should be told what style to program in.

python has roots in abc, an educational language and TOOWTDI (there's only one way to do it) is a recognised acronym on the dev list, so this prescriptive approach isn't new.

afaik python does "expensive" tail recursion (question - if a language supports first class continuations then can it still optimize away the previous environment on tail recursion?). also, reduce is foldr, not foldl (which seems odd - foldl is the tail recursive one and so, i guess, more popular). and, of course, python lists aren't lists, but arrays (interesting paper on implementing lists: http://ic2.epfl.ch/publications/documents/IC_TECH_REPORT_200244.pdf (from pragprog email list)).

[apologies if i'm confused about foldr/foldl - some of this comes from some old notes, which i'm now starting to doubt]

so no, python isn't a functional language. but count your lucky stars you're not using (generic) java. this is my declaration for foldl (and writing functions is even more verbose, requiring nests of inner classes).

public class Foldl<A,B>
implements Fn<Fn<Fn<A,List<B>>,A>,Fn<Fn<A,B>,A>>

Isaac Gouy - Re: PyCon 2003 Papers  blueArrow
4/19/2003; 8:14:20 AM (reads: 691, responses: 0)
<Any A> A foldLeft1(Sequence seq, (A, A)->A func)
With Nice, you can have functional cake (Haskell Prelude Examples) with your Java.

And to follow-up on Michael Vanier's comment: I think multimethods are one of the most underrated language features; the latest version of Nice allows multiple dispatch for methods declared in Java.

andrew cooke - Re: PyCon 2003 Papers  blueArrow
4/19/2003; 8:27:19 AM (reads: 776, responses: 0)
another related comment about fp in python - there was recently some debate about a ternary "if" operator (like "?" in c). the "deep" way to implement this would be to add laziness to the language. otherwise, if you don't want to construct explicit objects to delay evaluation, you can use a paremeter-less lambda expression as a parameter (which would then be evaluated on demand). someone dreamt up an elegant hack that made the syntax neater and required no changes to the language (giving ternary if as a special case). more info at http://groups.google.com/groups?threadm=2259b0e2.0303171358.5a6fe337%40posting.google.com&rnum=1

andrew cooke - Re: PyCon 2003 Papers  blueArrow
4/19/2003; 8:29:17 AM (reads: 691, responses: 0)
that's, err, nice. thanks.

Noel Welsh - Re: PyCon 2003 Papers  blueArrow
4/20/2003; 1:53:59 AM (reads: 670, responses: 0)
Its interesting to read that thread and contrast it with the attitude in the Scheme community where macros are commonplace. Note the many disclaimers that the code is "evil" and "macros are evil". I'm not trying to make a value judgement here (but as a Scheme hacker I suppose I can't avoid it ;-), just point out how the community expresses its values.

You can see the same thing in the Perl community when Larry Wall writes "it allows the S&M folks to inflict strongly typed compile-time semantics on each other. (Which is fine, as long as they don't inflict those semantics on the rest of us.)" The key word here being "us". Doses the Perl community value static typing?

Ok, enough amateur lit-crit from me.