On 12/19/11 3:38 PM, Eric Hodel wrote:
> On Dec 15, 2011, at 7:39 PM, Rodrigo Rosenfeld Rosas wrote:
>> Yeah, I already knew about all this. What I'm asking is why Ruby won't allow me to return from another method, ie, passing procs between different methods that will allow me to return from any method through that proc...
>>
>> I would like to know the reasoning behind this design decision... Is it just difficult technically to implement such behavior, or is it undesired? For the latter case, I would like to know why it is undesired...
>
> Continuations allow you to arbitrarily unwind the stack, but you probably want to avoid using them because they're tricky to use correctly:
>

Continuations allow more than just unwinding the stack; catch/throw 
might be a more suitable Ruby primitive for non-local exits that do not 
need unlimited extent.  Catch/throw is usually less resource intensive. 
  However, binding rtn to a unique catch "name" might be difficult:

def a x
   rtn = :rtn
   catch(rtn) do
     b(x, rtn) * 3
   end
end

def b x, rtn
   c(x, rtn) * 5
end

def c x, rtn
   case x
   when 1
     throw rtn, - x
   else
     x
   end
end


puts a(1)
puts a(2)