I have a simple search program that uses the each method with a yield to
pass back results as it finds it. However in depth first search the
method recurses at when it attempts the yield I get:
./search.rb:82:in each': no block given (LocalJumpError) from ./search.rb:77:ineach’
from ./search.rb:77:in `each’
The code is:
class DepthFirstSearch < GeneralSearch
def each(list = @partials)
# Declaring this variable outside the loop speeds things up
temp = ‘’
list.each {|p|
@nextitems.each {|n|
temp = [ p.map {|x|x}, n ].flatten
if is_valid(temp) then
if is_result(temp) then
@solutions += 1
yield temp
else
@checked += 1
each([temp])
end
end
}
}
end
end
I suspect the problem is, through various fiddling, that the code block
is not accessable to the subsequent recursion of the each method.
I have a simple search program that uses the each method with a yield to
pass back results as it finds it. However in depth first search the
method recurses at when it attempts the yield I get:
./search.rb:82:in `each': no block given (LocalJumpError)
from ./search.rb:77:in `each'
from ./search.rb:77:in `each'
The code is:
class DepthFirstSearch < GeneralSearch
def each(list = @partials)
should be:
def each(list = @partials, &block)
# Declaring this variable outside the loop speeds things up
temp = ''
list.each {|p| @nextitems.each {|n|
temp = [ p.map {|x|x}, n ].flatten
if is_valid(temp) then
if is_result(temp) then @solutions += 1
yield temp
else @checked += 1
each([temp])
each is called without block.
should be:
each([temp], &block)
end
end
}
}
end
end
I suspect the problem is, through various fiddling, that the code block
is not accessable to the subsequent recursion of the each method.
Any clues how to get this to work?
Regards,
Michael
···
On Mon, May 19, 2003 at 06:38:09PM +0900, Peter Hickman wrote: