[e-lang] Looser memoization and constant-folding: will this work?
Kevin Reid
kpreid at attglobal.net
Sat May 6 16:07:03 EDT 2006
On May 6, 2006, at 12:50, Mark S. Miller wrote:
> Kevin Reid wrote:
>> - Is this correct?
>
> I think so.
So far, testing agrees.
>> - Is there a way to handle the DeepFrozen-returns-DeepFrozen case
>> which does not involve two possibly-arbitrarily-expensive
>> evaluations?
>
...
> # map from msgs to good results
> def cache := [].asMap().diverge()
> # map from msgs to either null or [possible result]
> def dfCache := [].asMap().diverge()
...
> if (dfCache[msg] =~ [oldResult]) {
> if (df == oldResult) {
> # Happened again, so memoize it for real
> cache[msg] := df
...
Clever. Unfortunately, it won't work for constant folding since a
definite answer is needed the first time a particular call is seen.
I'll certainly try it for the memoizer, however.
--
Kevin Reid <http://homepage.mac.com/kpreid/>
More information about the e-lang
mailing list