fare / fare-memoization

MIT License
14 stars 4 forks source link

Reset memoization information #1

Open tsmacdonald opened 10 years ago

tsmacdonald commented 10 years ago

This is a feature request, not a bug.

It seems very cumbersome to me to only memoize information for the duration of a call in a recursive function. For example:

(fare-memoization:define-memo-function (memoized-edit-distance :table *results*) (source target scores) ...)
(defun edit-distance (source target &optional (scores (make-edit-scores)))
  (clrhash *results*)
  (memoized-edit-distance source target scores))

Using the library as-is, is there a saner way of doing this that I can't think of? If not, would there be interest in creating a new macro that captured the above pattern?

fare commented 10 years ago

Well, for now you can use dynamic binding, since it's a special variable:

(let ((results (make-hash-table ...))) ...)

If you come up with a syntax that makes sense in a general enough case, I might use it, but right I don't. clrhash looks like the wrong thing, because it's global, and you want something local.