Function: with-memoization

with-memoization is a macro defined in subr.el.gz.

Signature

(with-memoization PLACE &rest CODE)

Documentation

Return the value of CODE and stash it in PLACE.

If PLACE's value is non-nil, then don't bother evaluating CODE and return the value found in PLACE instead.

View in manual

Probably introduced at or before Emacs version 29.1.

Source Code

;; Defined in /usr/src/emacs/lisp/subr.el.gz
(defmacro with-memoization (place &rest code)
  "Return the value of CODE and stash it in PLACE.
If PLACE's value is non-nil, then don't bother evaluating CODE
and return the value found in PLACE instead."
  (declare (indent 1) (debug (gv-place body)))
  (gv-letplace (getter setter) place
    `(or ,getter
         ,(macroexp-let2 nil val (macroexp-progn code)
            `(progn
               ,(funcall setter val)
               ,val)))))