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 10:10:44 -0500 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <874o4l311n.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> <87k4dh3363.fsf@lifelogs.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1306163472 26004 80.91.229.12 (23 May 2011 15:11:12 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 23 May 2011 15:11:12 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon May 23 17:11:08 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 1QOWme-0001zr-Cf for ged-emacs-devel@m.gmane.org; Mon, 23 May 2011 17:11:04 +0200 Original-Received: from localhost ([::1]:41323 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOWmd-0008ES-SG for ged-emacs-devel@m.gmane.org; Mon, 23 May 2011 11:11:03 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:43694) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOWma-0008EF-ED for emacs-devel@gnu.org; Mon, 23 May 2011 11:11:01 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QOWmZ-0007hI-5R for emacs-devel@gnu.org; Mon, 23 May 2011 11:11:00 -0400 Original-Received: from lo.gmane.org ([80.91.229.12]:40815) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOWmY-0007hC-Pn for emacs-devel@gnu.org; Mon, 23 May 2011 11:10:59 -0400 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1QOWmX-0001sP-MV for emacs-devel@gnu.org; Mon, 23 May 2011 17:10:57 +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 17:10:57 +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 17:10:57 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 109 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:wsLMu7vr5UML9IOXtnQduMlkK70= 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:139650 Archived-At: --=-=-= Content-Type: text/plain On Mon, 23 May 2011 11:59:02 -0300 Stefan Monnier wrote: >> 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. SM> IIUC this will only be used by URL, at least at first. Is there any SM> other package which is likely to use it in the foreseeable "future"? SM> If not, then I'd recommend to name it "url-future" for now. The idea from the beginning was that this is a true data type, not an auxiliary library. At least deferred.el and fsm.el will use it, and I am in favor of adding deferred.el to Emacs as I mentioned. I would rather not isolate its scope to just URL interactions because rewriting url-future-* to future-* later will be annoying and because it makes the package look like it has narrow utility. SM> PS: I'd expect future-finish and future-errored to signal an error is SM> the future is already done-p. And future-call should return the SM> future-value. Thanks, I made those changes, see attached. 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-completed-p (future) (eq (future-status future) t)) (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) (if (future-done-p future) (signal 'future-already-done nil) (setf (future-status future) (or status t)) (when (future-callback future) (funcall (future-callback future) future)))) (defun future-errored (future error &optional signal) (if (future-done-p future) (signal 'future-already-done nil) (setf (future-status future) 'error) (setf (future-value future) signal) (when (future-errorback future) (funcall (future-errorback future) future error)))) (defun future-call (future) (if (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-value future))) (future-finish future))) (defun future-cancel (future) (if (future-done-p future) (signal 'future-already-done nil) (future-finish future 'cancel))) (provide 'future) ;;; future.el ends here --=-=-=--