From: Alex Gutteridge Date: 2007-10-23T13:36:14+09:00 Subject: Re: recursive array On 23 Oct 2007, at 13:08, Simon Schuster wrote: > also, I'm interested in what is going on "behind the scenes" here. is > a[4][4][4][4][0] actually reaching in 4 levels deep? It calls Array#[] 5 times if that's what you mean? But all on the same Array. It's turtles all the way down would be another way of putting it (or one turtle repeated over and over again). [alexg@powerbook]/Users/alexg/Desktop(31): cat test.rb a = [1,2,3,4] a[4] = a set_trace_func proc {|event,file,line,id,binding,classname| printf "%8s %s:%-2d %10s %8s\n",event,file,line,id,classname if event == "c-call" } a[4][4][4][4][0] [alexg@powerbook]/Users/alexg/Desktop(32): ruby test.rb c-call test.rb:8 [] Array c-call test.rb:8 [] Array c-call test.rb:8 [] Array c-call test.rb:8 [] Array c-call test.rb:8 [] Array > On 10/22/07, Simon Schuster wrote: >> 207:0> a = [1,2,3,4] >> [1, 2, 3, 4] >> 208:0> a[4] = a >> [1, 2, 3, 4, [...]] >> 209:0> a[4] >> [1, 2, 3, 4, [...]] >> 210:0> a[4][4] >> [1, 2, 3, 4, [...]] >> 211:0> a[4][4][4][4][4][3] >> 4 >> >> have you ever used this technique? can you provide some example code >> for us which illustrates any kind of usefulness of this that you can >> imagine? I have to say I can't imagine any practical use (obfuscation perhaps?), but maybe there are some fun games you can play with it. Alex Gutteridge Bioinformatics Center Kyoto University