News for hackers. Stuff that matters.
Re:Ruby-style Blocks in Python by sah on Sunday March 08, 2009 @04:44PM (#507516)
A similar feature was already proposed and rejected: http://www.python.org/dev/peps/pep-0340/

Anyway, I'm kind of sad that people seem to want a straight copy of Ruby's blocks. I'd prefer syntax that allowed passing more than one block to a function, like the C-like syntax I proposed here: http://www.hackerdashery.com/2006/10/code-blocks-and-c-like-...

Re:Ruby-style Blocks in Python by Jebdm on Sunday March 08, 2009 @10:19PM (#507834)
I was wondering if the one-block limit bothered anyone else. Maybe something like Haskell's where clause:

  map(foo, pairs) where:
    pairs = [(0,1), (20, 10), (30, 10)]
    def foo(pair):
      a = pair[1] * 2
      b = pair[0] * a
      return (b, a)
I'm not terribly familiar with Python's grammar, so it might be difficult to introduce a closing where-clause without ambiguity. In that case, it might be useful to use a do clause as well:

  do:
    <statements>
  where:
    <statements>
Another alternative would be to simply create a real function literal syntax (i.e., lambda that doesn't suck).
Re:Ruby-style Blocks in Python by jamongkad on Monday March 09, 2009 @03:01AM (#508065)
The only time I see where Python will adopt a lambda that doesn't suck, is the day when the community itself embraces functional programming. At the rate that is going and from what I've read from the commenters of the article. I don't think that's happening anytime soon.
Re:Ruby-style Blocks in Python by cturner on Monday March 09, 2009 @05:38AM (#508182)
I think that's right. Since the early days there have been lots of people willing to say (from an academic bent) how python is basically just scheme, and (from a practical bent) how the likes of python+libraries is good enough to make scheme unnecessary. Programming in scheme feels very different to scheme, largely because of the neutered lambda.
Re:Ruby-style Blocks in Python by russell on Sunday March 08, 2009 @09:03PM (#507752)
Actually 340 was withdrawn in favor of the 'with' statement, so blocks haven't been ruled out, as far as I can see. However, it will have to be Pythonic (no braces of block terminators) and well thought out.
Re:Ruby-style Blocks in Python by tav on Sunday March 08, 2009 @05:37PM (#507554)
@sah Nice! Sadly it wouldn't ever fly in the Python context, but I like it nevertheless!