Skip to content

Comment on Evils of the For Loop in Ruby

Comments

I don't get it. Isn't `|i|` the shorthand version of a lambda binding an i? And `lambda { i }` a lambda not binding anything? So why is the result surprising? I must be missing something.

Edit: I mean in

  each { |i| p i }
the |i| stands for a shorthand lambda, that binds an i.

And in

    for i in 1..3
      p i
    end
there is no such binding. So where's the problem? That 'for' should use a lambda?
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.