SystemStackError: stack level too deep

my code is ;

$ssf
def find_class(class_name, stack = [])
FileClass.find(:all, :conditions => [“class_name = ?”,
class_name]).each do |file_class|
FileInclude.find(:all, :conditions => [“file_name = ?”,
file_class.file_name]).each do |file_include|
FileClass.find(:all, :conditions => [“file_name = ?”,
file_include.file_name]).each do |xxxx|
next if stack.include?(xxxx.class_name)
begin
find_class(file_class.class_name, stack)

          p  file_class
          p "============================"
          p file_include
          p "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------"
          p xxxx
        rescue SystemStackError => ssf
          p $ssf = ssf
        end

    end
  end
end

end

rake aborted!
SystemStackError: stack level too deep: SELECT * FROM file_includes
WHERE (file_name = ‘IMAgentHome’)

C:/Base/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:212:in
log' C:/Base/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:320:inexecute’
C:/Base/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:595:in
`select’

help me please!

On Sep 3, 10:15 am, Ahmet K. [email protected]
wrote:

help me please!

Well you seem to be recursing in a pretty uncontrolled way.

Fred

Abhinav S. wrote:

You have not mentioned how should recursion stop properly. Anyway, code
also
doesnt look very clean and I think not very efficient too. My suggestion
is
first fetch all FileClass using conditions in an array, include all the
FileInclude as well (using :include) Then select, reject the record you
want
to.

Sorry, if I haven’t understood your problem correctly.


Thanks,
Abhinav
http://twitter.com/abhinav

On Thu, Sep 3, 2009 at 2:45 PM, Ahmet K. <

sorry, my code is not good one, but the code is here,

def find_class(class_name, stack = [])
puts(("\t" * stack.size) + class_name)

puts(("\t" * stack.size) + “#{class_name}”)

stack.push class_name
FileClass.find(:all, :conditions => [“class_name = ?”,
class_name]).each do |file_class|
FileInclude.find(:all, :conditions => [“file_name = ?”,
file_class.file_name]).each do |file_include|
FileClass.find(:all, :conditions => [“file_name = ?”,
file_include.file_name]).each do |file_class|
next if stack.include?(file_class.class_name)
find_class(file_class.class_name, stack)
end
end
end
stack.pop
end

I am testing which part is getting error…

first fetch all FileClass using conditions in an array, include all the
FileInclude as well (using :include) Then select, reject the record you
want

could you provide a simple example for this(using :include), please!

Hi,

Can you put in a statement what you are trying to do, probably then I
(and
others) will be able to help you better.


Thanks,
Abhinav
http://twitter.com/abhinav

On Thu, Sep 3, 2009 at 3:19 PM, Ahmet K. <

You have not mentioned how should recursion stop properly. Anyway, code
also
doesnt look very clean and I think not very efficient too. My suggestion
is
first fetch all FileClass using conditions in an array, include all the
FileInclude as well (using :include) Then select, reject the record you
want
to.

Sorry, if I haven’t understood your problem correctly.


Thanks,
Abhinav
http://twitter.com/abhinav

On Thu, Sep 3, 2009 at 2:45 PM, Ahmet K. <

Abhinav S. wrote:

Hi,

Can you put in a statement what you are trying to do, probably then I
(and
others) will be able to help you better.


Thanks,
Abhinav
http://twitter.com/abhinav

On Thu, Sep 3, 2009 at 3:19 PM, Ahmet K. <

thanks,
I improved my code, but still not enough
its giving me double result

def find_class(class_name, stack = [])
puts(("\t" * stack.size) + class_name)

stack.push class_name
FileClass.find(:all, :conditions => ["class_name = ?", 

class_name]).each do |file_class|
p file_class.file_name + “aaa”
FileInclude.find(:all, :conditions => [“file_name = ?”,
file_class.file_name]).each do |file_include|

      p file_include.include_file_name + "bbb"
      FileClass.find(:all, :conditions => ["file_name = ?", 

file_include.file_name]).each do |file_class|

      p file_class.class_name + "ccc"
      next if stack.include?(file_class.class_name)

      find_class(file_include.include_file_name, stack)
    end
  end
end

stack.pop
end


results

CTAgentHome
“CTAgentHome.haaa”
"“FWCTBase.h"bbb”
“CTAgentHomeRepccc”
“FWCTBase.h”
“CTAgentHomeccc”
"“FWMOBase.h"bbb”
“CTAgentHomeRepccc”
“FWMOBase.h”
“CTAgentHomeccc”
"“MOSAgentBasicInfo.h"bbb”
“CTAgentHomeRepccc”
“MOSAgentBasicInfo.h”
“CTAgentHomeccc”
"“MOSAgentCriteriaInfo.h"bbb”
“CTAgentHomeRepccc”
“MOSAgentCriteriaInfo.h”
“CTAgentHomeccc”
"“MOSAgentInfo.h"bbb”
“CTAgentHomeRepccc”
“MOSAgentInfo.h”
“CTAgentHomeccc”
"“MOSAgentMessageInfo.h"bbb”
“CTAgentHomeRepccc”
“MOSAgentMessageInfo.h”
“CTAgentHomeccc”
“CTAgentHomeRep.haaa”
"“FWMOBase.h"bbb”
“CTAgentHomeccc”
“CTAgentHomeRepccc”
“FWMOBase.h”
"“MOSAgentBasicInfo.h"bbb”
“CTAgentHomeccc”
“CTAgentHomeRepccc”
“MOSAgentBasicInfo.h”
"“MOSAgentCriteriaInfo.h"bbb”
“CTAgentHomeccc”
“CTAgentHomeRepccc”
“MOSAgentCriteriaInfo.h”
"“MOSAgentInfo.h"bbb”
“CTAgentHomeccc”
“CTAgentHomeRepccc”
“MOSAgentInfo.h”
"“MOSAgentMessageInfo.h"bbb”
“CTAgentHomeccc”
“CTAgentHomeRepccc”
“MOSAgentMessageInfo.h”

I made mistake somewhere but where…

Help me understand what you are trying to accomplish (please put in
words)

Thanks,
Abhinav
http://twitter.com/abhinav

On Thu, Sep 3, 2009 at 5:06 PM, Ahmet K. <

I am trying to recursive call. An the resut should be like this

resullts

CTAgentHome
FWCTBase.h
FWMOBase.h
MOSAgentBasicInfo.h
MOSAgentMessageInfo.h

I am tring to find CTAgentHome’s include classes.
I think it is clear now.

I think the problem is you are using the wrong algorithm to solve your
problem.

DFS (depth-first-search) algorithms will easily repeat sequences across
subtrees.

Starting at CTAgentHome:
CTAgentHome.h and CTAgentHomeRep.h both share the same [FWMOBase.h,
MOSAgentBasicInfo.h, MOSAgentCriteriaInfo.h,
MOSAgentInfo.hMOSAgentMessageInfo.h] subtrees.

By the time you’re back processing CTAgentHomeRep.h at level aaa, none
of those class_name’s previously seen exist on the stack anymore, so the
new recursive path doesn’t know that they’ve already been logged.

Or I really don’t grok your code, and I haven’t had nearly enough coffee
today.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs