Common Lisp Package: FARE-MEMOIZATION

README:

FUNCTION

Public

MEMOIZE (SYMBOL &KEY (TABLE (MAKE-HASH-TABLE TEST 'EQUAL)) NORMALIZATION)

Memoize the function associated to given SYMBOL. Beware that function was declared NOTINLINE, callers are not guaranteed to see the memoized function rather than have inlined the original one. Moreover, if the function is self-recursive, this declaration must have happened before it was defined. Keyword argument TABLE (default: a fresh EQUAL hash-table) lets you specify an existing hash-table for the memoized computations; it may have been created with appropriate options regarding equality predicate and weak pointers, initial contents, etc., and you may clear it when needed. Keyword argument NORMALIZATION (default: NIL) lets you specify a function taking a continuation and the function arguments, e.g. with lambda-list (CONTINUATION &REST ARGUMENTS) which may transform the argument list before to call the continuation with a normalized argument list that will be used to query the computation cache and invoke the actual computation function; NIL means no such transformation, which has the same effect as specifying #'APPLY as a transformation. If the function was already being memoized, any previous memoization information, i.e. TABLE and NORMALIZATION, is replaced with the newly specified values.

MEMOIZING (FUNCTION &REST KEYS &KEY TABLE NORMALIZATION)

Given a function, return a memoizing version of same function. Keyword arguments TABLE and NORMALIZATION are as per MEMOIZE.

UNMEMOIZE (SYMBOL)

undoing the memoizing function, return the memoization-info record for the function

UNMEMOIZE-1 (SYMBOL &REST ARGUMENTS)

Forget the memoized result of calling SYMBOL with arguments ARGUMENTS. Do not forget memoized results of calling the function with other arguments. Returns T if a stored result was found and removed, NIL otherwise.

Undocumented

MEMOIZED-APPLY (FUNCTION &REST ARGUMENTS)

MEMOIZED-FUNCALL (&REST ARGS)

Private

COMPUTE-MEMOIZED-FUNCTION (INFO ARGUMENTS)

the basic helper for computing with a memoized function FUNCTION, with a hash-table TABLE, being called with arguments ARGUMENTS

MACRO

Public

DEFINE-MEMO-FUNCTION (NAME FORMALS &BODY BODY)

Like defun, but creates a memoized function. Also, if the name is a CONS, then the first element is the name, and the rest is a list of keyword arguments, TABLE and NORMALIZATION as per MEMOIZE.

SLOT-ACCESSOR

Private

MEMOIZED-FUNCTION (OBJECT)

The original, unmemoized, function

MEMOIZED-NORMALIZATION (OBJECT)

either NIL or a function to normalize arguments before memoization

MEMOIZED-TABLE (OBJECT)

a hash-table containing the memoized computations so far

VARIABLE

Public

Undocumented

*MEMOIZED*

CLASS

Private

MEMOIZATION-INFO

information about a function that was memoized