Hello. My name is Piotr Szotkowski and I’m new to the list (and to
JRuby). Apologies if the below is a known issue or a FAQ; I tried
googling and searching through the list’s archive, but to no avail.
Now, my problem – a discrepancy in break handling between JRuby 1.1.1
and MRI 1.8.6.p114. After defining the below new Enumerable iterators:
module Enumerable
def every_pair_with_indices
each_with_index do |a, i|
each_with_index do |b, j|
yield [a, b, i, j] if i < j
end
end
end
def every_pair
every_pair_with_indices do |a, b, i, j|
yield [a, b]
end
end
end
JRuby and MRI give me different results:
ruby 1.8.6 (2008-03-03 patchlevel 114) [i686-linux]
>> [:a,:b,:c,:d].every_pair{|a,b| p [a,b]; break if [a,b] == [:a,:c]}
[:a, :b]
[:a, :c]
=> nil
ruby 1.8.6 (2008-04-22 rev 6555) [i386-jruby1.1.1]
>> [:a,:b,:c,:d].every_pair{|a,b| p [a,b]; break if [a,b] == [:a,:c]}
[:a, :b]
[:a, :c]
[:b, :c]
[:b, :d]
[:c, :d]
=> [:a, :b, :c, :d]
If I understand the things right, in JRuby the break only breaks
the innermost every_pair loop (i.e., it ‘unwinds’ it into two loops,
and breaks the inner one), while in MRI break actually breaks out of
every_pair.
Is this a known discrepancy, and if so, is there either a way to make
JRuby behave like MRI or a way to rewrite every_pair so it’s possible
to break out of it (in the same manner like out of Enumerable#each)?
-- Shot
on 15.05.2008 22:19
on 15.05.2008 22:51
On 15 May 2008, at 21:25, Shot (Piotr Szotkowski) wrote: > Hello. My name is Piotr Szotkowski and I’m new to the list (and to > JRuby). Apologies if the below is a known issue or a FAQ; I tried > googling and searching through the list’s archive, but to no avail. Hi Piotr, > Now, my problem – a discrepancy in break handling between JRuby 1.1.1 > and MRI 1.8.6.p114. I can confirm this is also an issue on jruby trunk. Could you file an issue with jira? <http://jira.codehaus.org/browse/JRUBY> Thanks, Damian --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 16.05.2008 09:55
Shot (Piotr Szotkowski): > ruby 1.8.6 (2008-03-03 patchlevel 114) [i686-linux] > >> [:a,:b,:c,:d].every_pair{|a,b| p [a,b]; break if [a,b] == [:a,:c]} > [:a, :b] > [:a, :c] > => nil > ruby 1.8.6 (2008-04-22 rev 6555) [i386-jruby1.1.1] > >> [:a,:b,:c,:d].every_pair{|a,b| p [a,b]; break if [a,b] == [:a,:c]} > [:a, :b] > [:a, :c] > [:b, :c] > [:b, :d] > [:c, :d] > => [:a, :b, :c, :d] > Is this a known discrepancy, and if so, is there > either a way to make JRuby behave like MRI FWIW: In my limited set of use cases, I worked around this by raising a custom exception and rescuing it after the loop. -- Shot
on 16.05.2008 10:15
On 16 May 2008, at 09:01, Shot (Piotr Szotkowski) wrote: > > FWIW: In my limited set of use cases, I worked around this > by raising a custom exception and rescuing it after the loop. > > -- Shot Thanks for posting a workaround, and for submitting a bug report. JRuby seems to have a few issues with break, having tried a few reductions. Damian --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email