35

GitHub - skeeto/emacs-memoize: Elisp memoization functions

 4 years ago
source link: https://github.com/skeeto/emacs-memoize
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md

Elisp memoization functions

See the header in the source file for details. It's very easy to use:

(require 'memoize)

(memoize 'my-function)

The macro defmemoize is also provided to directly create memoized functions:

(defmemoize my-expensive-function (n)
  (if (zerop n)
      1
    (* n (my-expensive-function (1- n)))))

Some functions are run over buffer contents, and need to be cached only so long as the buffer contents do not change. For these use-cases, we have the function memoize-by-buffer-contents as well as the defmemoize-by-buffer-contents macro.

To restore the original definition of a memoized function symbol (not a lambda or closure), use memoize-restore:

(memoize 'my-function)
(memoize-restore 'my-function)

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK