On Mon, Dec 09, 2002 at 08:36:20PM -0000, Smylers wrote: > I was wondering whether it'd be better to have this specified per > C<return> rather than per C<sub>. That'd permit something a long the > lines of: > > sub days_in_month(Str $month, Int $year) > { > .... > } > > Perhaps there are only some edge cases which require calculation; or the > function is liable to be called with many invalid input values, which > can quickly be determined yield C<undef> and so which don't need > caching; or there is a pattern as to which sets of input parameters are > likely to be passed multiple times so the function only bother caching > those.
It doesn't matter whether some of the values are cheap lookups while other values are "complex calculations". Once a cached sub is called with a set of parameter values, the return value will always be a cheap lookup in the memoized sub's cache. It's irrelevant if you have a different but comparable "cheap lookup" for some values. > Anybody else like this, or are we better off leaving things as they > were? I think you're trying to overoptimize something here. I can't see a benefit to caching only sometimes. If there is, then you probably want to implement a more sophisticated cache management strategy for your sub, not warp the language for a special case. Z.