News for hackers. Stuff that matters.
Re:What Pythonistas Think of Ruby by mclin on Wednesday February 03, 2010 @11:34AM (#1098081)
I'm not sure I get the lambda issue. If you want a > 1 line lambda why not just define a function?

    def a(x):
        def b():
           print x
        return b
Not sure what a prototypical ruby usecase would be.
Re:What Pythonistas Think of Ruby by gcampbell on Wednesday February 03, 2010 @12:35PM (#1098264)
The other side of the argument: why support anonymous functions, but restrict them to one line? That seems highly arbitrary.
Re:What Pythonistas Think of Ruby by fuzzyman on Wednesday February 03, 2010 @12:45PM (#1098293)
Nope - not arbitrary, it is because of the indentation scoping rules. Try coming up with a syntax for statement based lambdas that isn't ugly as heck.
Re:What Pythonistas Think of Ruby by jashkenas on Wednesday February 03, 2010 @01:18PM (#1098410)
First, links for context.

Guido's take: http://www.artima.com/weblogs/viewpost.jsp?thread=147358

Arcieri's take: http://www.unlimitednovelty.com/2009/03/indentation-sensitiv...

It's not hard if we disallow statements, and make everything into an expression that returns a value -- something that Ruby does right. The value of a block of statements is just the value of the last statement in the block.

So, whether you call it a function, or a method, or a lambda, or a block, whitespace with multi-line expressions can be made to work.

The commonly-cited lambda-with-multiple-prints example, in CoffeeScript:

    count: ->
      print 'one'
      print 'two'
      print 'three'
Re:What Pythonistas Think of Ruby by kevingadd on Wednesday February 03, 2010 @12:43PM (#1098285)
Not one line, one statement.
Re:What Pythonistas Think of Ruby by 0x44 on Wednesday February 03, 2010 @07:07PM (#1099324)
The prototypical ruby case would be:

  def some_method(x, &block)
    yield x
  end

  then to call it:

  some_method "hey" { |v| print v }
That might not look like much, but it allows you to create methods that can extend the language expressively and then use them without extra crufty syntax or sigils obstructing their meaning.
Re:What Pythonistas Think of Ruby by mclin on Wednesday February 03, 2010 @08:39PM (#1099512)
> some_method "hey" { |v| print v }

I'm sure ruby is great once you're initiated, but despite >10 years of programming and having learned basic, c, pascal, lisp, java, c++, python, perl, bash, php and javascript, I have no idea what code does.

Don't mean to harsh, just an observation.

Re:What Pythonistas Think of Ruby by 0x44 on Thursday February 04, 2010 @11:47AM (#1100889)
I made that method absurdly generic, how about:

  get "/hi" do |url|
    print url
  end

?
Re:What Pythonistas Think of Ruby by brutimus on Wednesday February 03, 2010 @01:01PM (#1098351)
I don't understand the argument either.. I use multi-line lambdas with ifs and forloops all the time.

  f = lambda x:(
    x if (
      x**2 > 10 or x**2 < 5
    )
    else x**3
  )
Re:What Pythonistas Think of Ruby by cturner on Wednesday February 03, 2010 @01:30PM (#1098439)
I don't think you can assign variables in these blocks, nor do sequential statements. Imagine you wanted to reduce a list, and then do something on it. Print statements don't work either.