diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2023-01-10 10:38:43 +0100 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2023-01-10 10:41:50 +0100 |
| commit | edfad44bfb382b3f464e27dd6ae72cbbd7793618 (patch) | |
| tree | 14d5a945e09cf303972e81a04ea9bceb7dd8ae23 /compat-29.el | |
| parent | 2514d35259a1a1abef90ccc9be9e903ec9b70e78 (diff) | |
compat-29: Add with-memoization
Diffstat (limited to 'compat-29.el')
| -rw-r--r-- | compat-29.el | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/compat-29.el b/compat-29.el index abb9346..6250a89 100644 --- a/compat-29.el +++ b/compat-29.el @@ -177,6 +177,18 @@ This function does not move point. Also see `line-end-position'." ;;;; Defined in subr.el +(compat-defmacro with-memoization (place &rest code) ;; <OK> + "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)) + (gv-letplace (getter setter) place + `(or ,getter + ,(macroexp-let2 nil val (macroexp-progn code) + `(progn + ,(funcall setter val) + ,val))))) + (compat-defalias string-split split-string) ;; <OK> (compat-defun function-alias-p (func &optional noerror) ;; <OK> |
