From: Charles Oliver Nutter Date: 2008-01-03T15:35:20+09:00 Subject: Re: Inconsistency in rescuability of "return" Gary Wright wrote: > > On Jan 2, 2008, at 7:15 PM, Jano Svitok wrote: > >> On Jan 3, 2008 12:53 AM, Gary Wright wrote: >>> >>> On Jan 2, 2008, at 6:31 PM, Charles Oliver Nutter wrote: >>>> But when eval'ing a break outside a while, it does propagate an >>>> error. So the code under eval is changing its behavior depending on >>>> what structures surround it. That seems wrong to me, and it means >>>> that any implementations wanting to emulate it will have to >>>> maintain state across calls, so eval knows it's being called within >>>> a loop. >>> >>> I don't see how this is any different than the other examples. When >>> "eval 'break'" is inside the while loop, 'break' doesn't cause an >>> error, it simply breaks out of the loop. If you put "eval 'break'" >>> at the top level you've got your local jump error again, right? >> >> The issue is that eval result depends on one more variable - whether >> the call is inside a loop or not. >> So it's a function of it's parameters, data, AND previous calls (or >> how you would call it). > > Yes, but the behavior of 'break' itself is dependent on the context. So > it is the semantics of 'break' that seems to be in question in this > example, not the semantics of 'eval' and the semantics of break in this > example are 'normal' as far as I can tell: > > A) break (via eval or not) outside of a loop context causes an exception > B) break (via eval or not) inside a loop context causes the loop to be > terminated > > If this is problematic, what behavior would you expect for A and B? The problem with this logic is that in case A, the exception also causes the loop to be terminated as normal: while true eval 'break' end So there's obviously some duality behind break. 1. A bare break can't be cause as an exception, and terminates an enclosing loop 2. A break inside an eval can be caught as an exception, and also terminates an enclosing loop like a normal break. - Charlie