Created
November 1, 2010 04:34
-
-
Save kurohuku/657610 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defclass promise () | |
((action :initarg :action :initform (error "Required :action")) | |
(is-called-p :initform nil) | |
(result :initform nil))) | |
(defmacro delay (action) | |
`(make-instance 'promise :action (lambda () ,action))) | |
(defun force (promise) | |
(if (slot-value promise 'is-called-p) | |
(slot-value promise 'result) | |
(let ((r (funcall (slot-value promise 'action)))) | |
(setf (slot-value promise 'is-called-p) t | |
(slot-value promise 'result) r) | |
r))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment