1 ;;; thunk.el --- Lazy form evaluation -*- lexical-binding: t -*-
3 ;; Copyright (C) 2015 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 <http://www.gnu.org/licenses/>.
29 ;; Thunk provides functions and macros to control the evaluation of
30 ;; forms. Use `thunk-delay' to delay the evaluation of a form, and
31 ;; `thunk-force' to evaluate it. Evaluation is cached, and only
34 ;; Tests are located at test/automated/thunk-tests.el
38 (defmacro thunk-delay (&rest body)
39 "Delay the evaluation of BODY."
41 (let ((forced (make-symbol "forced"))
42 (val (make-symbol "val")))
44 (lambda (&optional check)
48 (setf ,val (progn ,@body))
52 (defun thunk-force (delayed)
53 "Force the evaluation of DELAYED.
54 The result is cached and will be returned on subsequent calls
55 with the same DELAYED argument."
58 (defun thunk-evaluated-p (delayed)
59 "Return non-nil if DELAYED has been evaluated."
63 ;;; thunk.el ends here