From: Brian Candler Date: 2003-04-12T06:56:41+09:00 Subject: Re: splat question On Sat, Apr 12, 2003 at 05:39:05AM +0900, Chris Pine wrote: > This sounds like lazy evaluation, the kind of stuff you can find around > implemented with continuations. > ---------------------------- > > Well, it might sound that way, but it really isn't. :) > > Lazy evaluation is much more involved and deep; I was only talking about a > difference in implementation. > > For example, when I give Ruby the following: > > bar = [2, 3, 4] > foo = [0, 1, *bar] > > it could internally store that array just like it looks: as an array of > three elements, but also distinguishing between pointers-to-elements and > pointers-to-splats. As a workaround you can always nest arrays, infinitely so if you wish. I think your first example was a = [1, *a] Well, you can't do that, but you can write: a = [1] a << a in which case you get an infinite recursive structure, except it's [1, [1, [1, .... ]]] instead of [1, 1, 1, .....] Not only inspect but other parts of ruby handle this properly, e.g. irb(main):010:0> a.flatten! ArgumentError: tried to flatten recursive array from (irb):10:in `flatten!' And I guess: bar = [2, 3, 4] foo = [0, 1, bar] p foo.flatten is sort of like the example you gave above. In fact, perhaps you could define class Splat < Array which would let you do foo = [0, 1, Splat.new(bar)] and modify Array#each so that it iterates over (flattens) the elements of a Splat automatically... Regards, Brian.