From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thien-Thi Nguyen Newsgroups: gmane.emacs.devel Subject: Re: ELisp futures and continuations/coroutines Date: Sun, 22 May 2011 15:17:32 +0200 Message-ID: <87tycmzxg3.fsf@ambire.localdomain> References: <87fwogaxzb.fsf@stupidchicken.com> <87mxilezg8.fsf@lifelogs.com> <87boz0eov8.fsf@lifelogs.com> <87mxikrulm.fsf@lifelogs.com> <871uzw5asv.fsf@lifelogs.com> <878vu2ztua.fsf_-_@lifelogs.com> <87oc2ywwuy.fsf@ambire.localdomain> <87r57uyaeu.fsf@lifelogs.com> <87hb8qwsmo.fsf@ambire.localdomain> <87oc2yuu8u.fsf@lifelogs.com> <87d3jew4eq.fsf@ambire.localdomain> <8739k9s84c.fsf@lifelogs.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1306070340 16050 80.91.229.12 (22 May 2011 13:19:00 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 22 May 2011 13:19:00 +0000 (UTC) Cc: emacs-devel@gnu.org To: Ted Zlatanov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun May 22 15:18:56 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QO8Ya-0007iy-4T for ged-emacs-devel@m.gmane.org; Sun, 22 May 2011 15:18:56 +0200 Original-Received: from localhost ([::1]:59716 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QO8YZ-0003NQ-HY for ged-emacs-devel@m.gmane.org; Sun, 22 May 2011 09:18:55 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:53174) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QO8YX-0003NJ-1m for emacs-devel@gnu.org; Sun, 22 May 2011 09:18:53 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QO8YV-0007kJ-Nu for emacs-devel@gnu.org; Sun, 22 May 2011 09:18:53 -0400 Original-Received: from smtp204.alice.it ([82.57.200.100]:52812) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QO8YV-0007k3-9a for emacs-devel@gnu.org; Sun, 22 May 2011 09:18:51 -0400 Original-Received: from ambire.localdomain (79.0.68.154) by smtp204.alice.it (8.5.124.08) id 4D7E0F6406124BF3; Sun, 22 May 2011 15:18:46 +0200 Original-Received: from ttn by ambire.localdomain with local (Exim 4.69) (envelope-from ) id 1QO8XE-0003rN-E4; Sun, 22 May 2011 15:17:32 +0200 In-Reply-To: <8739k9s84c.fsf@lifelogs.com> (Ted Zlatanov's message of "Fri, 20 May 2011 10:29:39 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 82.57.200.100 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:139621 Archived-At: () Ted Zlatanov () 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 =E2=80=98future=E2=80=99 struct =E2=80=98future=E2= =80=99 I guess there will be similarities between the fsm and deferred glue that we'd be wise to "move" into =E2=80=98struct future=E2=80=99, but that remai= ns to be seen. --=20 a sig, not big, i fig, you dig?