From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Thien-Thi Nguyen Newsgroups: gmane.emacs.devel Subject: Re: run-with-timer vs run-with-idle-timer Date: Thu, 10 May 2018 20:50:50 +0200 Message-ID: <87603v4a5x.fsf@gnuvola.org> References: <87tvrgd972.fsf@gmail.com> <87a7t74tsf.fsf@gnuvola.org> Reply-To: emacs-devel NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-Trace: blaine.gmane.org 1526022281 13010 195.159.176.226 (11 May 2018 07:04:41 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 11 May 2018 07:04:41 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: =?utf-8?B?Sm/Do28gVMOhdm9yYQ==?= To: emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri May 11 09:04:37 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fH26W-0003GP-DA for ged-emacs-devel@m.gmane.org; Fri, 11 May 2018 09:04:36 +0200 Original-Received: from localhost ([::1]:37041 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH28d-000260-Jv for ged-emacs-devel@m.gmane.org; Fri, 11 May 2018 03:06:47 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50233) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH27b-00024W-2M for emacs-devel@gnu.org; Fri, 11 May 2018 03:05:44 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fH27X-0003k2-39 for emacs-devel@gnu.org; Fri, 11 May 2018 03:05:43 -0400 Original-Received: from mail.agora-net.com ([67.59.132.6]:38405) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fH27W-0003jk-U7 for emacs-devel@gnu.org; Fri, 11 May 2018 03:05:39 -0400 Original-Received: from ttn by mail.agora-net.com with local (Exim 4.82) (envelope-from ) id 1fH27V-0003Ua-Mx; Fri, 11 May 2018 03:05:37 -0400 Original-Received: from ttn by zigzag.favinet with local (Exim 4.80) (envelope-from ) id 1fGqeb-0004ie-DW; Thu, 10 May 2018 20:51:01 +0200 Mail-Followup-To: emacs-devel In-Reply-To: (=?utf-8?Q?=22Jo=C3=A3o_T=C3=A1vora=22's?= message of "Thu, 10 May 2018 13:28:20 +0100") X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: ttn@gnuvola.org X-SA-Exim-Scanned: No (on mail.agora-net.com); SAEximRunCond expanded to false X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 67.59.132.6 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.emacs.devel:225222 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable () Jo=C3=A3o T=C3=A1vora () Thu, 10 May 2018 13:28:20 +0100 I'm using throw/catch because there are lambdas setup inside that block (but outside the while t). Inside the lambda is the throw. I then store these lambdas in a global CONTINUATIONS var that the process filter looks up and calls if appropriate. The infloop breaks then. If you can structure whatever =E2=80=98catch=E2=80=99es the =E2=80=98throw= =E2=80=99s to mutate state visible to CONDITION, then you can use =E2=80=98while CONDITION=E2=80= =99. If that state is dynamic (e.g., declared w/ =E2=80=98defvar=E2=80=99), you = can can reconfigure the =E2=80=98throw=E2=80=99 to simply mutate it directly, a= nd eliminate the =E2=80=98catch=E2=80=99 part (and still use =E2=80=98while CO= NDITION=E2=80=99). It's much harder (and much less efficient at first sight) to do it by polling CONDITION, but I may be missing something. Hmmm. Let me know if you want to look at a concrete example of the lambda strategy. I'd appreciate seeing a skeleton of the code, because what i imagine it to be is probably not exactly what it is. (I could be misunderstanding your description grossly.) BTW I learned this strategy reading SLIME, I just simplified it when lexical binding came along. It's been working there and in other projects for a long time. I confess i've never looked deeply at SLIME innards. Aside from some simple toys, my only deep experience w/ async code is w/ gnugo.el -- in func =E2=80=98gnugo--q=E2=80=99 you can see: (while (process-get proc :incomplete) (accept-process-output proc 30)) Here, CONDITION is =E2=80=98(process-get proc :incomplete)=E2=80=99 and the process filter is the one responsible for evaluating: (process-put proc :incomplete nil) The state is not in a variable but in a process object property (named =E2=80=98:incomplete=E2=80=99). Its value is initialized to =E2=80= =98t=E2=80=99 prior to looping. The change from =E2=80=98t=E2=80=99 to =E2=80=98nil=E2=80=99 brea= ks the loop. Another precision to note is that the =E2=80=98accept-process-output=E2=80=99 1st a= rg is specified. I believe (but have never actually measured) this helps performance slightly. This has also worked for quite a while. I suppose it's a matter of style. I feel uncomfortable writing =E2=80=98while t=E2=80=99 + =E2=80=98throw=E2=80=99 (or similar) in gnugo.e= l because one of its design goals (fulfilled, AFAICT, knock on wood! :-D) is to be able to play multiple games simultaneously (i.e., run multiple independent child processes), and greedily spinning borks that. =2D-=20 Thien-Thi Nguyen ----------------------------------------------- (defun responsep (query) (pcase (context query) (`(technical ,ml) (correctp ml)) ...)) 748E A0E8 1CB8 A748 9BFA =2D-------------------------------------- 6CE4 6703 2224 4C80 7502 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAlr0lI4ACgkQZwMiJEyAdQKpiACbBkr/1PeFCOnSaHD8ZzWkaTDU DvQAnibCbrRxrrvhC9Jh+nmGsMPh7sgY =TBTE -----END PGP SIGNATURE----- --=-=-=--