Why?

hi all,
def foo(string)
arr=[string]
puts arr
arr.each do |b|
foo(b)
end
end
foo("foobar")
this results in an endless loop.. (though it gives SystemStackError)
but why doesn't this go any deeper than one level?

require 'find'
def index(dir, filename=dir)
list=[]
dirs=[]
Find.find(dir) do |filename|
list << filename.split(/\/|\.\//)

end
list.each do |file|
if file.length < 3
puts file
else
dirs << file[0]
end
end
dirs.each do |name|
index(name)
end
end

index(".","index")

i just don't see it..

greetings, Dirk.

[snip badly formated code]

def foo(string)
  arr = [string]
  puts arr
  arr.each do |b|
    foo(b)
  end
end
foo("foobar")

That is a very complicated way of writing

def foo(a)
  foo(a)
end
foo("foobar")

What do you want to achieve here?

require 'find'
def index(dir, filename=dir)
list=
dirs=
Find.find(dir) do |filename|
list << filename.split(/\/|\.\//)

end
list.each do |file|
if file.length < 3
puts file
else
dirs << file[0]
end
end
dirs.each do |name|
index(name)
end
end

index(".","index")

i just don't see it..

greetings, Dirk.

What do you want to achieve with the above. I suppose you'll get
better answers if you describe your problem than by submitting
obfuscated code.

cheers,

Brian

···

On 07/11/05, Dirk Meijer <hawkman.gelooft@gmail.com> wrote:

--
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/

Ruby 1.8.3 omits the duplicate frames:

$ ruby
def x() x end
x
-:1:in `x': stack level too deep (SystemStackError)
         from -:1:in `x'
         from -:2
$ ruby -v
ruby 1.8.3 (2005-09-21) [powerpc-darwin8.2.0]

1.8.2 and earlier do not:

$ ruby182-orig
def x() x end
x
-:1:in `x': stack level too deep (SystemStackError)
         from -:1:in `x'
          ... 1105 levels...
         from -:1:in `x'
         from -:2
$ ruby182-orig -v
ruby 1.8.2 (2004-12-25) [powerpc-darwin8.0]

···

On Nov 7, 2005, at 7:10 AM, Dirk Meijer wrote:

hi all,
def foo(string)
arr=[string]
puts arr
arr.each do |b|
foo(b)
end
foo("foobar")
this results in an endless loop.. (though it gives SystemStackError)
but why doesn't this go any deeper than one level?

--
Eric Hodel - drbrain@segment7.net - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

hi,
i want my program to print all files and directories in a given directory,
then print files and dirs in subdirectories, without it showing the name of
the subdirectory..
but for some reason, it doesn't execute the method again for the
subdirectories found in the current directory..
greetings, Dirk.

···

2005/11/7, Brian Schröder <ruby.brian@gmail.com>:

On 07/11/05, Dirk Meijer <hawkman.gelooft@gmail.com> wrote:
> [snip badly formated code]

def foo(string)
arr = [string]
puts arr
arr.each do |b|
foo(b)
end
end
foo("foobar")

That is a very complicated way of writing

def foo(a)
foo(a)
end
foo("foobar")

What do you want to achieve here?

>
> require 'find'
> def index(dir, filename=dir)
> list=
> dirs=
> Find.find(dir) do |filename|
> list << filename.split(/\/|\.\//)
>
> end
> list.each do |file|
> if file.length < 3
> puts file
> else
> dirs << file[0]
> end
> end
> dirs.each do |name|
> index(name)
> end
> end
>
> index(".","index")
>
> i just don't see it..
>
> greetings, Dirk.
>
>

What do you want to achieve with the above. I suppose you'll get
better answers if you describe your problem than by submitting
obfuscated code.

cheers,

Brian

--
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/

no need to write a recursive function:

   ruby -e' Dir["**/**"].each{|e| puts(File::basename(e))} '

hth.

-a

···

On Tue, 8 Nov 2005, Dirk Meijer wrote:

i want my program to print all files and directories in a given directory,
then print files and dirs in subdirectories, without it showing the name of
the subdirectory.. but for some reason, it doesn't execute the method again
for the subdirectories found in the current directory.. greetings, Dirk.

--

email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
anything that contradicts experience and logic should be abandoned.
-- h.h. the 14th dalai lama

===============================================================================

Dirk Meijer wrote:

hi,
i want my program to print all files and directories in a given
directory, then print files and dirs in subdirectories, without it
showing the name of the subdirectory..
but for some reason, it doesn't execute the method again for the
subdirectories found in the current directory..
greetings, Dirk.

You probably get an endless recursion because you don't exclude "." and
".." from the recursion.

You can make your life much easier by using Find. Try this:

ruby -r find -e 'Find.find(".") {|f| puts f}'

Kind regards

    robert

i am using Find::find, but i got it to only display files and dirs in
current directory, not to do the same with subdirectories..
greetings, Dirk.

···

2005/11/7, Robert Klemme <bob.news@gmx.net>:

Dirk Meijer wrote:
> hi,
> i want my program to print all files and directories in a given
> directory, then print files and dirs in subdirectories, without it
> showing the name of the subdirectory..
> but for some reason, it doesn't execute the method again for the
> subdirectories found in the current directory..
> greetings, Dirk.

You probably get an endless recursion because you don't exclude "." and
".." from the recursion.

You can make your life much easier by using Find. Try this:

ruby -r find -e 'Find.find(".") {|f| puts f}'

Kind regards

robert

Dirk Meijer wrote:

i am using Find::find, but i got it to only display files and dirs in
current directory, not to do the same with subdirectories..
greetings, Dirk.

Did you try my one liner? Are there sub directories? You're probably
trying to implement the recursion yourself - you must not do that because
that's all Find.find is about...

Kind regards

    robert

···

2005/11/7, Robert Klemme <bob.news@gmx.net>:

Dirk Meijer wrote:

hi,
i want my program to print all files and directories in a given
directory, then print files and dirs in subdirectories, without it
showing the name of the subdirectory..
but for some reason, it doesn't execute the method again for the
subdirectories found in the current directory..
greetings, Dirk.

You probably get an endless recursion because you don't exclude "."
and ".." from the recursion.

You can make your life much easier by using Find. Try this:

ruby -r find -e 'Find.find(".") {|f| puts f}'

Kind regards

robert

i started out with your suggestion, but i need it to first display files and
dirs in current directory, then do the same for the subdirectories..
ruby -r find -e 'Find.find(".") {|f| puts f}'
prints everything at once, which wouldn't work in this case, as i want it to
export to different html files (one for each directory) but i need to get
this to work first..
greetings, Dirk.

···

2005/11/7, Robert Klemme <bob.news@gmx.net>:

Dirk Meijer wrote:
> i am using Find::find, but i got it to only display files and dirs in
> current directory, not to do the same with subdirectories..
> greetings, Dirk.

Did you try my one liner? Are there sub directories? You're probably
trying to implement the recursion yourself - you must not do that because
that's all Find.find is about...

Kind regards

robert

>
> 2005/11/7, Robert Klemme <bob.news@gmx.net>:
>>
>> Dirk Meijer wrote:
>>> hi,
>>> i want my program to print all files and directories in a given
>>> directory, then print files and dirs in subdirectories, without it
>>> showing the name of the subdirectory..
>>> but for some reason, it doesn't execute the method again for the
>>> subdirectories found in the current directory..
>>> greetings, Dirk.
>>
>> You probably get an endless recursion because you don't exclude "."
>> and ".." from the recursion.
>>
>> You can make your life much easier by using Find. Try this:
>>
>> ruby -r find -e 'Find.find(".") {|f| puts f}'
>>
>> Kind regards
>>
>> robert

Dirk Meijer wrote:

i started out with your suggestion, but i need it to first display
files and dirs in current directory, then do the same for the
subdirectories..
ruby -r find -e 'Find.find(".") {|f| puts f}'
prints everything at once, which wouldn't work in this case, as i
want it to export to different html files (one for each directory)
but i need to get this to work first..
greetings, Dirk.

Then you're likely better off using a combination of Find.find and Dir
like this:

ruby -r find -e 'Find.find(".") {|f| if File.directory? f then puts f; p
Dir[File.join(f,"*")] end}'

    robert

···

2005/11/7, Robert Klemme <bob.news@gmx.net>:

Dirk Meijer wrote:

i am using Find::find, but i got it to only display files and dirs
in current directory, not to do the same with subdirectories..
greetings, Dirk.

Did you try my one liner? Are there sub directories? You're probably
trying to implement the recursion yourself - you must not do that
because that's all Find.find is about...

Kind regards

robert

2005/11/7, Robert Klemme <bob.news@gmx.net>:

Dirk Meijer wrote:

hi,
i want my program to print all files and directories in a given
directory, then print files and dirs in subdirectories, without it
showing the name of the subdirectory..
but for some reason, it doesn't execute the method again for the
subdirectories found in the current directory..
greetings, Dirk.

You probably get an endless recursion because you don't exclude "."
and ".." from the recursion.

You can make your life much easier by using Find. Try this:

ruby -r find -e 'Find.find(".") {|f| puts f}'

Kind regards

robert

this does print the files in proper order, but the point is that i need the
method to be run multiple times in order to export to multiple html files..
for some reason though, my recursion only runs once, and it doesn't run the
method for the subdirectories in the subdirectories..
greetings, Dirk.

···

2005/11/7, Robert Klemme <bob.news@gmx.net>:

Dirk Meijer wrote:
> i started out with your suggestion, but i need it to first display
> files and dirs in current directory, then do the same for the
> subdirectories..
> ruby -r find -e 'Find.find(".") {|f| puts f}'
> prints everything at once, which wouldn't work in this case, as i
> want it to export to different html files (one for each directory)
> but i need to get this to work first..
> greetings, Dirk.

Then you're likely better off using a combination of Find.find and Dir
like this:

ruby -r find -e 'Find.find(".") {|f| if File.directory? f then puts f; p
Dir[File.join(f,"*")] end}'

robert

>
>
> 2005/11/7, Robert Klemme <bob.news@gmx.net>:
>>
>> Dirk Meijer wrote:
>>> i am using Find::find, but i got it to only display files and dirs
>>> in current directory, not to do the same with subdirectories..
>>> greetings, Dirk.
>>
>> Did you try my one liner? Are there sub directories? You're probably
>> trying to implement the recursion yourself - you must not do that
>> because that's all Find.find is about...
>>
>> Kind regards
>>
>> robert
>>
>>>
>>> 2005/11/7, Robert Klemme <bob.news@gmx.net>:
>>>>
>>>> Dirk Meijer wrote:
>>>>> hi,
>>>>> i want my program to print all files and directories in a given
>>>>> directory, then print files and dirs in subdirectories, without it
>>>>> showing the name of the subdirectory..
>>>>> but for some reason, it doesn't execute the method again for the
>>>>> subdirectories found in the current directory..
>>>>> greetings, Dirk.
>>>>
>>>> You probably get an endless recursion because you don't exclude "."
>>>> and ".." from the recursion.
>>>>
>>>> You can make your life much easier by using Find. Try this:
>>>>
>>>> ruby -r find -e 'Find.find(".") {|f| puts f}'
>>>>
>>>> Kind regards
>>>>
>>>> robert

this does print the files in proper order, but the point is that i
need the method to be run multiple times in order to export to
multiple html files.. for some reason though, my recursion only runs
once, and it doesn't run the method for the subdirectories in the
subdirectories..
greetings, Dirk.

Hey, where's your creativity? You can do the exporting in find's block. If that does not work, please state your complete requirements and what you are trying to achieve.

    robert

···

Dirk Meijer <hawkman.gelooft@gmail.com> wrote:

2005/11/7, Robert Klemme <bob.news@gmx.net>:

Dirk Meijer wrote:

i started out with your suggestion, but i need it to first display
files and dirs in current directory, then do the same for the
subdirectories..
ruby -r find -e 'Find.find(".") {|f| puts f}'
prints everything at once, which wouldn't work in this case, as i
want it to export to different html files (one for each directory)
but i need to get this to work first..
greetings, Dirk.

Then you're likely better off using a combination of Find.find and
Dir like this:

ruby -r find -e 'Find.find(".") {|f| if File.directory? f then puts
f; p Dir[File.join(f,"*")] end}'

robert

2005/11/7, Robert Klemme <bob.news@gmx.net>:

Dirk Meijer wrote:

i am using Find::find, but i got it to only display files and dirs
in current directory, not to do the same with subdirectories..
greetings, Dirk.

Did you try my one liner? Are there sub directories? You're
probably trying to implement the recursion yourself - you must not
do that because that's all Find.find is about...

Kind regards

robert

2005/11/7, Robert Klemme <bob.news@gmx.net>:

Dirk Meijer wrote:

hi,
i want my program to print all files and directories in a given
directory, then print files and dirs in subdirectories, without
it showing the name of the subdirectory..
but for some reason, it doesn't execute the method again for the
subdirectories found in the current directory..
greetings, Dirk.

You probably get an endless recursion because you don't exclude
"." and ".." from the recursion.

You can make your life much easier by using Find. Try this:

ruby -r find -e 'Find.find(".") {|f| puts f}'

Kind regards

robert