I get the following error:
perm.rb:17: [BUG] rb_gc_mark(): unknown data type 0x34(0x8a69570) non object
ruby 1.8.1 (2004-04-24) [i686-linux-gnu]
Ruben
···
===================================================================
class GeneratingPermutationWithState
attr_accessor :orig_str, :value
def initialize(str)
@orig_str = str
@cont = nil
@value = nil
@found = false
end
def recursive_each(chars_left,chars_built)
if chars_left.empty?
@value = chars_built.pack("c*")
@found = true
callcc {|@cont|} <============== error happens on this line
else
(0..(chars_left.length-1)).each { |index|
return if @found
new_char = chars_left[index]
new_chars_left = chars_left.clone
new_chars_left.delete_at(index)
new_chars_built = chars_built.clone
new_chars_built << new_char
recursive_each(new_chars_left,new_chars_built)
}
end
end
def start
arr = @orig_str.unpack('c*')
recursive_each(arr,Array.new())
end
def get_value
if (@value == nil) then
start
if @found then
return @value
else
return nil
end
else
@found = false
@cont.call
end
end
end
b = GeneratingPermutationWithState.new("abcdefghij")
while (b.get_value != nil)
end