Skip to content

Instantly share code, notes, and snippets.

@kurohuku
Created November 1, 2010 04:34
Show Gist options
  • Save kurohuku/657610 to your computer and use it in GitHub Desktop.
Save kurohuku/657610 to your computer and use it in GitHub Desktop.
(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