Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The answer seems obvious; it's the same behavior "return" has, i.e. it returns from the function it's currently in, not something a few levels up.


It might seem obvious, but Ruby, for example:

  def lambda_test
    lam = lambda { return }
    lam.call
    puts "Hello world"
  end

This will print "hello world". But this:

  def proc_test
    proc = Proc.new { return }
    proc.call
    puts "Hello world"
  end
Will print nothing, as the 'return' returns from proc_test. Examples taken from here: http://awaxman11.github.io/blog/2013/08/05/what-is-the-diffe...


Wow, that's a pretty nonsensical semantic. Thankfully, Rust is fairly sensible.


It makes more sense in-context; I did Ruby for years and never had to think about this once.


It gets used most to enable returning from the outer function while within loop-body-like procs. Rust iterators used to be like that too (pre-1.0), but they switched to the current style to get rid of that complexity.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: