From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.devel Subject: Re: ELisp futures and continuations/coroutines Date: Mon, 23 May 2011 09:24:52 -0500 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <87k4dh3363.fsf@lifelogs.com> 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> <87tycmzxg3.fsf@ambire.localdomain> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1306160715 6679 80.91.229.12 (23 May 2011 14:25:15 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 23 May 2011 14:25:15 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon May 23 16:25:12 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 1QOW4E-0003kd-OU for ged-emacs-devel@m.gmane.org; Mon, 23 May 2011 16:25:11 +0200 Original-Received: from localhost ([::1]:32889 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOW4E-0004dy-9V for ged-emacs-devel@m.gmane.org; Mon, 23 May 2011 10:25:10 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:50442) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOW4A-0004Xu-Cy for emacs-devel@gnu.org; Mon, 23 May 2011 10:25:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QOW49-00062q-36 for emacs-devel@gnu.org; Mon, 23 May 2011 10:25:06 -0400 Original-Received: from lo.gmane.org ([80.91.229.12]:56479) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOW48-000610-NC for emacs-devel@gnu.org; Mon, 23 May 2011 10:25:05 -0400 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1QOW47-0003fh-6C for emacs-devel@gnu.org; Mon, 23 May 2011 16:25:03 +0200 Original-Received: from 38.98.147.130 ([38.98.147.130]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 23 May 2011 16:25:03 +0200 Original-Received: from tzz by 38.98.147.130 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 23 May 2011 16:25:03 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 101 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: 38.98.147.130 X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6; d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" User-Agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:l8E8QCUWUoMNFI0DDnJJVXoO0ow= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 80.91.229.12 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:139646 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit On Sun, 22 May 2011 15:17:32 +0200 Thien-Thi Nguyen wrote: TN> () Ted Zlatanov TN> () Fri, 20 May 2011 10:29:39 -0500 TZZ> Let's get this done, simple though it is, and then see how it will TZZ> integrate with fsm.el and deferred.el. I really think it will benefit TZZ> everyone to start simple. ... TN> The next step (speaking from an armchair designer's pov) would be TN> to rebase fsm.el and deferred.el onto this data structure. Stefan, Chong, anyone else, please let me know if you have objections to the attached future.el package. I will add error handling and add it to Emacs tonight if there are no objections. It's pretty simple code. TN> I guess there will be similarities between the fsm and deferred glue that TN> we'd be wise to "move" into ‘struct future’, but that remains to be seen. I'll gladly modify it if we find such similarities once we start reworking fsm.el and deferred.el to use it. Ted --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=future.el Content-Transfer-Encoding: quoted-printable ;;; future.el --- general futures facility ;; Copyright (C) 2011 Teodor Zlatanov ;; Author: Teodor Zlatanov ;; Keywords: data ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;;; Code: (eval-when-compile (require 'cl)) (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 &optional signal) (unless (future-done-p future) (setf (future-status future) 'error) (setf (future-value future) signal) (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 and to call future-errored (setf (future-value future) (funcall ff)))) (future-finish future))) (defun future-cancel (future) (unless (future-done-p future) (future-finish future 'cancel))) (provide 'future) ;;; future.el ends here --=-=-=--