Re: map/filter/reduce/lambda opinions and background unscientific mini-survey



Tom Anderson wrote:
So, if you're a pythonista who loves map and lambda, and disagrees with Guido, what's your background? Functional or not?

I have no functional language background. Until recently, I had no use for programming "expression to be evaluated later" or "deferred expressions" or whatever else they are being called.


Where I came to see the awesomeness of "deferred expressions" was a few months ago when I started a major rewrite of KirbyBase for Ruby. I wanted to make the Ruby version of KirbyBase take advantage of the strengths of the language. Another Ruby programmer, Hal Fulton, was helping me by constantly pushing me to make KirbyBase more Ruby-ish. One thing he kept pushing was to be able to specify select querys using Ruby's "deferred expression" mechanism, code blocks (before anyone starts yelling, I know that Ruby code blocks are *much* more than just "deferred expressions"; I'm just using that descriptor here for the sake of this discussion).

Code blocks allow you to wrap up any Ruby code and pass it to a method and have it executed within that method. It is more powerful than lambda, because you can have multiple statements in the code block and you can do assignment within the code block. This allowed me to rewrite KirbyBase so that you can do a select like this:

plane_tbl.select { |r| r.country == 'USA' and r.speed > 350 }

Now, this is cool, but you can do this using lambda in Python. Where Ruby code blocks really shine is that you can also do this:

plane_tbl.update {|r| r.name == 'P-51'}.set {|r|
    r.speed = 405
    r.range = 1210
}

I have one code block that I pass to the update method which says "Select all planes with name equal to P-51". Then, I pass a code block to the set method which assigns new values to the speed and range fields for those records (i.e. P-51) that were selected in the update method. This is something you can't do with lambda.

Now, I think I can duplicate the same functionality of Ruby code blocks by using Python functions, but it is not going to be as pretty.

So, even though lambda is not as powerful as Ruby code blocks, I was still bummed to read that it is going away, because it is better than nothing.

Hopefully, Guido will reconsider or, even better, give us something even more powerful.

Jamey Cribbs
.



Relevant Pages

  • Re: new here, my lang project...
    ... >> I would say that Lambda calculus and lambda expressions are very ... code blocks which may be more than that originally expected. ... Again this is related to the type of dynamicbehaviour change at ...
    (comp.object)
  • Re: I sing the praises of lambda, my friend and savior!
    ... > which using lambda is preferable to using a generic variable-argument ... With code blocks, you could implement something like this instead: ... I'm not really convinced that their usefulness demands syntax extension. ... and TBH haven't used any of those languages. ...
    (comp.lang.python)
  • Re: I sing the praises of lambda, my friend and savior!
    ... is lambda is going away? ... They keep threatening it, ... Don't beg for code blocks again today ... Don't beg for code blocks again in the next three days ...
    (comp.lang.python)
  • Making a custom PageParser
    ... I want to make my own PageParser, to implement some functionality ... currently missing from standard one, ... * Code blocks which are marked with % in first line ...
    (microsoft.public.dotnet.framework.aspnet)