3 ms·
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.
by wyager 10y ago
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.
- steveklabnik 10y agoIt 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-difference-between-a-block/ http://awaxman11.github.io/blog/2013/08/05/what-is-the-diffe...
- wyager 10y agoWow, that's a pretty nonsensical semantic. Thankfully, Rust is fairly sensible.
- Rusky 10y agoIt 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.
- steveklabnik 10y agoIt makes more sense in-context; I did Ruby for years and never had to think about this once.