1 ;;; thunk.el --- Lazy form evaluation -*- lexical-binding: t -*-
3 ;; Copyright (C) 2015-2018 Free Software Foundation, Inc.
5 ;; Author: Nicolas Petton <nicolas@petton.fr>
10 ;; Maintainer: emacs-devel@gnu.org
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
29 ;; Thunk provides functions and macros to delay the evaluation of
32 ;; Use `thunk-delay' to delay the evaluation of a form, and
33 ;; `thunk-force' to evaluate it. The result of the evaluation is
34 ;; cached, and only happens once.
36 ;; Here is an example of a form which evaluation is delayed:
38 ;; (setq delayed (thunk-delay (message "this message is delayed")))
40 ;; `delayed' is not evaluated until `thunk-force' is called, like the
43 ;; (thunk-force delayed)
47 (defmacro thunk-delay
(&rest body
)
48 "Delay the evaluation of BODY."
50 (let ((forced (make-symbol "forced"))
51 (val (make-symbol "val")))
53 (lambda (&optional check
)
57 (setf ,val
(progn ,@body
))
61 (defun thunk-force (delayed)
62 "Force the evaluation of DELAYED.
63 The result is cached and will be returned on subsequent calls
64 with the same DELAYED argument."
67 (defun thunk-evaluated-p (delayed)
68 "Return non-nil if DELAYED has been evaluated."
72 ;;; thunk.el ends here