[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ELisp futures and continuations/coroutines
From: |
Thien-Thi Nguyen |
Subject: |
Re: ELisp futures and continuations/coroutines |
Date: |
Sun, 22 May 2011 15:17:32 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
() Ted Zlatanov <address@hidden>
() Fri, 20 May 2011 10:29:39 -0500
[knowledge of time is design, not implementation, thus out of scope
of the proposed "future type"]
Ok, i can respect that.
Let's get this done, simple though it is, and then see how it will
integrate with fsm.el and deferred.el. I really think it will benefit
everyone to start simple.
#+begin_src lisp
(defstruct future callback errorback status value)
(defun future-done-p (future)
(future-status future))
(defun future-errored-p (future)
(eq (future-status future) 'error))
(defun future-cancelled-p (future)
(eq (future-status future) 'cancel))
(defun future-finish (future &optional status)
(unless (future-done-p future)
(setf (future-status future) (or status t))
(when (future-callback future)
(funcall (future-callback future) future))))
(defun future-errored (future error)
(unless (future-done-p future)
(setf (future-status future) 'error)
(when (future-errorback future)
(funcall (future-errorback future) future error))))
(defun future-call (future)
(unless (future-done-p future)
(let ((ff (future-value future)))
(when (functionp ff)
;; TODO: needs error handling
(setf (future-value future)
(funcall ff))))
(future-finish future)))
(defun future-cancel (future)
(unless (future-done-p future)
(future-finish future 'cancel)))
#+end_src
The next step (speaking from an armchair designer's pov) would be
to rebase fsm.el and deferred.el onto this data structure.
before: fsm: deferred:
API API
internals internals
after: fsm: deferred:
API API
fsm glue deferred glue
struct ‘future’ struct ‘future’
I guess there will be similarities between the fsm and deferred glue that
we'd be wise to "move" into ‘struct future’, but that remains to be seen.
--
a sig, not big, i fig, you dig?
- Re: ELisp futures and continuations/coroutines, (continued)
- Re: ELisp futures and continuations/coroutines, Thien-Thi Nguyen, 2011/05/19
- Re: ELisp futures and continuations/coroutines, Ted Zlatanov, 2011/05/19
- Re: ELisp futures and continuations/coroutines, Thien-Thi Nguyen, 2011/05/19
- Re: ELisp futures and continuations/coroutines, Ted Zlatanov, 2011/05/19
- Re: ELisp futures and continuations/coroutines, Thien-Thi Nguyen, 2011/05/19
- Re: ELisp futures and continuations/coroutines, Mohsen BANAN, 2011/05/20
- Re: ELisp futures and continuations/coroutines, Ted Zlatanov, 2011/05/20
- Re: ELisp futures and continuations/coroutines, Ted Zlatanov, 2011/05/20
- Re: ELisp futures and continuations/coroutines,
Thien-Thi Nguyen <=
- Re: ELisp futures and continuations/coroutines, Ted Zlatanov, 2011/05/23
- Re: ELisp futures and continuations/coroutines, Stefan Monnier, 2011/05/23
- Re: ELisp futures and continuations/coroutines, Ted Zlatanov, 2011/05/23
- Re: ELisp futures and continuations/coroutines, SAKURAI Masashi, 2011/05/23
- Re: ELisp futures and continuations/coroutines, Ted Zlatanov, 2011/05/24
- Re: ELisp futures and continuations/coroutines, SAKURAI Masashi, 2011/05/25
- Re: ELisp futures and continuations/coroutines, Stefan Monnier, 2011/05/23
- Re: ELisp futures and continuations/coroutines, Ted Zlatanov, 2011/05/24
- Re: ELisp futures and continuations/coroutines, Ted Zlatanov, 2011/05/31
- Re: ELisp futures and continuations/coroutines, Ted Zlatanov, 2011/05/31