add defcached for memoization

for #84
This commit is contained in:
vindarel 2025-01-17 17:53:16 +01:00
parent 4e5485ad98
commit 687472719f
3 changed files with 28 additions and 0 deletions

View file

@ -142,6 +142,8 @@
:serapeum
:shlex
:function-cache ;; memoization
;; tests
:fiveam

View file

@ -183,6 +183,8 @@ And there is more. All the available macros are:
## Functions
### Partial application
We import Serapeum's `partial` and Alexandria's `rcurry`. They allow
partial application of functions.
@ -194,6 +196,25 @@ You can check [Serapeum's function helpers](https://github.com/ruricolist/serape
the non-imported ones are only a `serapeum` package prefix away in CIEL if you need
them. Other noticeable functions: `distinct`, `once`, `throttle`, `trampoline`, `do-nothing`
### Memoization
We import `defcached` from
[function-cache](https://github.com/AccelerationNet/function-cache), a
library that provides extensible caching/memoization.
For example:
```lisp
(defcached (foo :timeout 10) (arg)
(sleep 3)
arg)
```
Run `(foo 1)`, it sleeps 3 seconds and returns 1. Run `(foo 1)` again
and it returns 1 immediately. Its result (for this argument) is cached
for 10 seconds.
## Bind, more destructuring in `let` (metabang-bind)

View file

@ -290,6 +290,11 @@ We currently only try this with serapeum. See *deps/serapeum/sequences-hashtable
(export '(apropos-regex
apropos-regex-list))
;; function-cache: memoization
(cl-reexport:reexport-from :function-cache
:include '(:defcached)) ;; not in binary??
;;;
;;; Conveniently add type declarations.
;;; Straight from Serapeum, only it is -> thus it conflicts with our arrow-macro.