[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Odd break behavior?

Thomas E Enebo

2/18/2006 4:41:00 PM

Run the code snippet below:

class A
def outer
inner do
break
end
end

def inner
while true
yield
end
puts "Should never appear"
end
end

['something'].each do
A.new.outer
puts "1"
end

A.new.outer
puts "2"

Then comment out the something each block and rerun it. The first
run will look like:
1
2

The second run will look like:
Should never appear
2

For consistencies sake, I would have expected the first run to look like:
1
Should never appear
2

By virtue of previously calling outer in a block the second call to outer
now has different behavior (even though to me they look totally unrelated).
Can someone explain why this is?

-Tom

--
+ http://www.tc.umn.... +---- mailto:enebo@acm.org ----+
| Thomas E Enebo, Protagonist | "Luck favors the prepared |
| | mind." -Louis Pasteur |


2 Answers

Thomas E Enebo

2/18/2006 5:15:00 PM

0

On Sun, 19 Feb 2006, Yukihiro Matsumoto defenestrated me:
> In message "Re: Odd break behavior?"
> on Sun, 19 Feb 2006 01:40:48 +0900, Thomas E Enebo <enebo@acm.org> writes:
>
> | Run the code snippet below:
>
> <snip>
>
> It seems to be a bug. Thank you for finding it. It's too complex to
> fix it in a minute.

I am trying to determine the proper behavior to fix break in jruby.
Was what I expected the proper behavior?

-Tom

--
+ http://www.tc.umn.... +---- mailto:enebo@acm.org ----+
| Thomas E Enebo, Protagonist | "Luck favors the prepared |
| | mind." -Louis Pasteur |


Yukihiro Matsumoto

2/20/2006 1:00:00 AM

0

Hi,

In message "Re: Odd break behavior?"
on Sun, 19 Feb 2006 02:14:37 +0900, Thomas E Enebo <enebo@acm.org> writes:

| I am trying to determine the proper behavior to fix break in jruby.
|Was what I expected the proper behavior?

"break" should always terminate the lexically innermost loop or block.
In this case, invocation of "inner" should have been terminated. A
bug cause termination of while loop (the closest loop in dynamic call
graph) in the definition of "inner" erroneously.

matz.