Skip to content

Commit

Permalink
Define once with define-train.
Browse files Browse the repository at this point in the history
  • Loading branch information
ruricolist committed Mar 27, 2020
1 parent b84ae62 commit 6aba6d5
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions functions.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ between calls."
(throttle/memoized fn)
(throttle/simple fn)))))

(defmacro _once (fn)
(define-train once (fn)
"Return a function that runs FN only once, caching the results
forever."
(with-unique-names (gfn)
`(let ((,gfn (ensure-function ,fn))
(cache '())
Expand All @@ -255,14 +257,6 @@ between calls."
:not-first-run
(return (values-list cache))))))))

(defun once (fn)
"Return a function that runs FN only once, caching the results
forever."
(_once fn))

(define-compiler-macro once (fn)
`(_once ,fn))

(defun juxt (&rest fns)
"Clojure's `juxt'.
Expand Down

0 comments on commit 6aba6d5

Please sign in to comment.