From: Chris Pine Date: 2003-04-12T05:39:05+09:00 Subject: Re: splat question ----- Original Message ----- From: "Mauricio Fern�ndez" > Would this be impossible because when a splat is encountered, the objects > are injected into the other array at that moment? (It seems like Ruby could > just wait on that.) ========== > > It's just one of those things from functional programming that I don't see > how to do in Ruby. 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. Of course, `foo.length' should be still be 5; all of the implementation would be under the hood and invisible to the programmer. For all I know (I rarely look at the interpreter code), Ruby might do this already! We wouldn't be able to tell. The only real difference that I see is that this underlying implementation would allow for infinite arrays. `inspect' would be a little tricky, and loops would need to be detected (but `inspect' already does this, so it wouldn't be too big of a leap). Well, now that I think about it, perhaps it wouldn't be of much use without lazy evaluation. I could still get the array_of_ones[500] with the above implementation, but I wouldn't be able to write a function to pairwise add infinite arrays, for example, and get an array_of_twos. Would continuations really allow this sort of thing? I don't see how you would use continuations to give you lazy evaluation or infinite arrays. Chris