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: Thu, 19 May 2011 18:48:49 -0500 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <87oc2yuu8u.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> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1305848954 21317 80.91.229.12 (19 May 2011 23:49:14 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 19 May 2011 23:49:14 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri May 20 01:49:10 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 1QNCxo-0000Wt-NQ for ged-emacs-devel@m.gmane.org; Fri, 20 May 2011 01:49:09 +0200 Original-Received: from localhost ([::1]:40845 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QNCxo-000861-1K for ged-emacs-devel@m.gmane.org; Thu, 19 May 2011 19:49:08 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:56227) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QNCxk-00085h-PV for emacs-devel@gnu.org; Thu, 19 May 2011 19:49:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QNCxj-0006KR-JY for emacs-devel@gnu.org; Thu, 19 May 2011 19:49:04 -0400 Original-Received: from lo.gmane.org ([80.91.229.12]:45087) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QNCxj-0006KG-2Y for emacs-devel@gnu.org; Thu, 19 May 2011 19:49:03 -0400 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1QNCxh-0000TO-Up for emacs-devel@gnu.org; Fri, 20 May 2011 01:49:01 +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 ; Fri, 20 May 2011 01:49:01 +0200 Original-Received: from tzz by 38.98.147.130 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 20 May 2011 01:49:01 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 77 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:Wvty4AE9s7Z6/7dWlRuKu8CGM9s= 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:139536 Archived-At: On Thu, 19 May 2011 18:40:47 +0200 Thien-Thi Nguyen wrote: TN> i don't know what such a future type would do. ... TN> i would guess that a "future type" would be some subset of the fsm TN> internals. Why tie futures to fsm.el or deferred.el specifically? That seems like an implementation detail. I'd rather establish a futures API: - create a future - is it done? - get result - inspect thrown error, if any which is simple, obviously, but it's essential so all the implementations that use it speak the same language. TN> Analogous to the "keymap type", which is really just a list with symbol TN> ‘keymap’ in its CAR, i am guessing one could poke around fsm internals TN> and derive a "future type", without having to go to C. TN> Which is to say, i also don't know enough to say, but i see a similarity. Yes, it could be that way, or it could be a defstruct as in the deferred.el Masashi-san posted. Ideally no C code would be needed. I like the defstruct because it's simple yet has structure and accessor functions. I would copy the deferred defstruct without the `next' or `cancel' fields and without any callback/errorback defaults. Here's a first cut, pretty trivial code: #+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-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))) #+end_src `future-errored-p' breaks if the return value is 'error, though the correct callback will be invoked even then. I like the name "future" because it's fairly standard nowadays, it's a noun unlike "deferred," there are no global functions or variables with that string in Emacs except some org-mode variables, and it's very clear. If the above looks OK I can finish the implementation (error handling in `future-call' and around the callback/errorback invocations). Then any library can use ":include future" to add its own details on top of the `future' defstruct. Ted