[e-lang] Looser memoization and constant-folding: will this work?

David Wagner daw at cs.berkeley.edu
Fri May 19 10:09:57 EDT 2006


Kevin Reid <kpreid at attglobal.net> writes:
>It occurred to me that a simple fix would be to evaluate the call  
>twice, and see whether the result object is different; since the  
>call's parts are DeepFrozen, it can only be either always the same or  
>always different.
>
>   - Is there a way to handle the DeepFrozen-returns-DeepFrozen case  
>which does not involve two possibly-arbitrarily-expensive evaluations?

Currently you implement the cache with a map
  call -> result
where call = (receiver, arg1, .., argn).

You could store additional information in each cache entry,
implementing the cache with a map
  call -> cacheentry
where
  cacheentry = Once(result) | Cached(result) | NotMemoizable
Here is an interpretation of these various states:
  Once(r): We've evaluated this call exactly once before, and got the
    answer r in response.  We don't know yet whether we can memoize it.
  Cached(r): We've evaluated this call at least twice before, and we got
    the same answer r both times.  This call can be safely memoized.
  NotMemoizable: We've evaluated this call at least twice before, and we
    got two different answers.  This call cannot be safely memoized.

This has the disadvantage that it might require a lot of storage, because
you end up remembering all the invocations that cannot be cached.

I apologize for my late response.  I don't know whether this will help.


More information about the e-lang mailing list