[e-lang] Non-transparent memoization: is this safe?
Kevin Reid
kpreid at attglobal.net
Wed May 17 17:33:28 EDT 2006
Context:
E-on-CL includes a memoizer which takes a DeepFrozen object and
returns a DeepFrozen result which memoizes all calls in which the
arguments are DeepFrozen and the result is DeepPassByCopy.
http://www.eros-os.org/pipermail/e-lang/2006-May/011207.html shows
how to extend the memoizer to results that are DeepFrozen and not
different after each call.
Question:
Is it OK to consider safe a memoizer which instead memoizes results
if they are just DeepFrozen?
This would be non-transparent in that it behaves differently from the
original reference, but it would not be unsafe, in that it is
equivalent to a DeepFrozen object which has references to the results
of every call that will ever be made to it.
In other words, this would allow selective lazy evaluation.
I believe <import> already provides a limited form of this, in that
it caches any result-of-an-emaker that is DeepFrozen. The memoizer
would extend this by allowing the specification of arbitrary
functions to be memoized, rather than the static set of all emakers.
Reasons why adding this would be useful:
- It allows additional memoization for efficiency purposes,
because it is simple to make an object DeepFrozen and complex to make
it Selfless; consider quasi-parsers:
memoize(
def foo__quasiParser implements DeepFrozen {
to valueMaker(template) :any {
return def vm implements DeepFrozen { to substitute ... }
}
}
)
I believe E-on-CL would benefit greatly from this.
- It makes <import> less magical, by allowing unprivileged
construction of more of its behavior.
- It may help fix an unrelated problem with <import> which I will
post later.
--
Kevin Reid <http://homepage.mac.com/kpreid/>
More information about the e-lang
mailing list