Re: Partially Memoized Functions

2002-12-12 Thread James Mastros
On 12/10/2002 5:46 PM, Smylers wrote: OK. There was something on MJD's QOTW recently where using the current Perl 5 Memoize module slowed code down -- that gave me the impression that caching had the potential. It does. In fact, all caching has that potential. Specificly, if the time to look

Re: Partially Memoized Functions

2002-12-10 Thread Adam Turoff
On Tue, Dec 10, 2002 at 01:53:28PM +1100, Damian Conway wrote: And in those rare cases where you really do need partial caching, the simplest solution is to split the partially cached subroutine into a fully cached sub and an uncached sub: sub days_in_month(Str $month, Int $year) {

Re: Partially Memoized Functions

2002-12-10 Thread Adam Turoff
On Mon, Dec 09, 2002 at 01:58:11PM -0800, Austin Hastings wrote: --- Adam Turoff [EMAIL PROTECTED] wrote: 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

Re: Partially Memoized Functions

2002-12-10 Thread Adam Turoff
On Mon, Dec 09, 2002 at 01:58:11PM -0800, Austin Hastings wrote: --- Adam Turoff [EMAIL PROTECTED] wrote: 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

Re: Partially Memoized Functions

2002-12-10 Thread Adam Turoff
On Mon, Dec 09, 2002 at 02:20:01PM -0800, Austin Hastings wrote: --- Paul Johnson [EMAIL PROTECTED] wrote: How about the same way as one would do it now? Presumably we won't all forget how to program when Perl 6 comes out. I think you've missed the point. The original poster (Smylers)

Re: Partially Memoized Functions

2002-12-10 Thread Smylers
Michael G Schwern wrote: On Mon, Dec 09, 2002 at 08:36:20PM -, Smylers wrote: That way a function could decide to cache some return values but not all of them. The example above is a classic example of premature optimization. There's nothing which ways the cache would be

Re: Partially Memoized Functions

2002-12-10 Thread Michael G Schwern
On Tue, Dec 10, 2002 at 10:46:07PM -, Smylers wrote: The example above is a classic example of premature optimization. There's nothing which ways the cache would be counter-productive for simple calculations since the caching logic is nearly as simple. OK. There was something on

Re: Partially Memoized Functions

2002-12-10 Thread Damian Conway
Adam Turoff wrote: sub days_in_month(Str $month, Int $year) { $month = lc $month; if $month eq 'feb' { my sub feb_days (Int $year) is cached { my $leap = $year % 4 == 0 ($year % 100 != 0 || $year % 400 == 0); return $leap ? 29 : 28; } return

Re: Partially Memoized Functions

2002-12-09 Thread Adam Turoff
On Mon, Dec 09, 2002 at 08:36:20PM -, Smylers wrote: I was wondering whether it'd be better to have this specified per Creturn rather than per Csub. That'd permit something a long the lines of: sub days_in_month(Str $month, Int $year) { } Perhaps there are only some

Re: Partially Memoized Functions

2002-12-09 Thread Austin Hastings
--- Adam Turoff [EMAIL PROTECTED] wrote: On Mon, Dec 09, 2002 at 08:36:20PM -, Smylers wrote: 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 Cundef and so

Re: Partially Memoized Functions

2002-12-09 Thread Paul Johnson
On Mon, Dec 09, 2002 at 01:58:11PM -0800, Austin Hastings wrote: --- Adam Turoff [EMAIL PROTECTED] wrote: On Mon, Dec 09, 2002 at 08:36:20PM -, Smylers wrote: Anybody else like this, or are we better off leaving things as they were? I think you're trying to overoptimize

Re: Partially Memoized Functions

2002-12-09 Thread Austin Hastings
--- Paul Johnson [EMAIL PROTECTED] wrote: On Mon, Dec 09, 2002 at 01:58:11PM -0800, Austin Hastings wrote: Ahh. This is better. How does one implement a more sophisticated cache management strategy? That is, what is the mechanism for manipulating the run-time system behavior of subs?

Re: Partially Memoized Functions

2002-12-09 Thread Paul Johnson
On Mon, Dec 09, 2002 at 02:20:01PM -0800, Austin Hastings wrote: --- Paul Johnson [EMAIL PROTECTED] wrote: On Mon, Dec 09, 2002 at 01:58:11PM -0800, Austin Hastings wrote: Ahh. This is better. How does one implement a more sophisticated cache management strategy? That is, what is

Re: Partially Memoized Functions

2002-12-09 Thread Michael G Schwern
On Mon, Dec 09, 2002 at 08:36:20PM -, Smylers wrote: Last month's discussion on memoization[*0] had the consensus that Ccached is the appropriate property name, used like so: sub square (Num $n) is cached { ... } I was wondering whether it'd be better to have this specified per

Re: Partially Memoized Functions

2002-12-09 Thread Damian Conway
Smylers wrote: I was wondering whether it'd be better to have this specified per Creturn rather than per Csub. I doubt it. There's no performance gain from partial caching since you have to check the cache anyway to detect that a particular result isn't cached. And in those rare cases where