From: David Masover Date: 2008-06-08T06:46:34+09:00 Subject: Re: storing values for later use On Saturday 07 June 2008 15:53:49 progcat@comcast.net wrote: > Example: My program calculates the first 1000 elements of a function. > My c function can calculate all 1000 elements > in about the same time as it take to calculate the 999'th element, so > rather calling c over and over is way too slow! > > This function can have 1 to 6 parameters that are unknown until run > time > so I can't just "set them up" in advance. Depends what you mean by "in advance". Sounds like you had the right idea with the hash, but probably better to wrap it in some sort of object. For example: class BigCStuff ... def function_I_want_to_put_off *args @argument_lists << args end ... def [] i self.result_array[i] end def result_array @result_array ||= actual_C_call(@argument_lists) end end I'm trying not to make too many assumptions about what you're doing here... > (I think this is the "opposite" of a lazy function. By the way, what I've done above is actually a lazy object of sorts.