From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nic Ferrier Newsgroups: gmane.emacs.devel Subject: Re: RFC: Generators v2 Date: Sun, 25 Aug 2013 09:28:19 +0100 Message-ID: <87vc2uyy1o.fsf@ferrier.me.uk> References: <52198EF7.50900@dancol.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1377419320 17391 80.91.229.3 (25 Aug 2013 08:28:40 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 25 Aug 2013 08:28:40 +0000 (UTC) To: Emacs development discussions Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Aug 25 10:28:41 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VDVge-0007mM-P9 for ged-emacs-devel@m.gmane.org; Sun, 25 Aug 2013 10:28:40 +0200 Original-Received: from localhost ([::1]:45331 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VDVge-0006RT-8q for ged-emacs-devel@m.gmane.org; Sun, 25 Aug 2013 04:28:40 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34319) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VDVgW-0006RI-Bn for emacs-devel@gnu.org; Sun, 25 Aug 2013 04:28:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VDVgQ-0004fL-UB for emacs-devel@gnu.org; Sun, 25 Aug 2013 04:28:32 -0400 Original-Received: from static.17.66.46.78.clients.your-server.de ([78.46.66.17]:36224 helo=po1.ferrier.me.uk) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VDVgQ-0004ef-NU for emacs-devel@gnu.org; Sun, 25 Aug 2013 04:28:26 -0400 Original-Received: from nferrier-Dell-System-XPS-L322X (140.35.155.90.in-addr.arpa [90.155.35.140]) by po1.ferrier.me.uk (Postfix) with ESMTP id 65EEBAC05E2; Sun, 25 Aug 2013 10:33:26 +0200 (CEST) Original-Received: from nics-xps (localhost [127.0.0.1]) by nferrier-Dell-System-XPS-L322X (Postfix) with ESMTP id 1E3598C040D; Sun, 25 Aug 2013 09:28:19 +0100 (BST) In-Reply-To: <52198EF7.50900@dancol.org> (dancol@dancol.org's message of "Sat, 24 Aug 2013 21:58:31 -0700") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 78.46.66.17 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:163010 Archived-At: dancol@dancol.org writes: > At https://github.com/dcolascione/elisp-generators, I've updated my > elisp generator support. Please take a look. > > Since the last version, I've added documentation, cl-loop > integration, a few more testcases, and a lexical-binding assertion. > > I'd eventually like to integrate this package into > the Emacs core, so I've laid claim to a few symbols in the > global namespace, like next. This package actually defines a generic > iterator protocol, and it'd be useful eventually to define iterator > objects for things like buffers and windows instead of relying on > enumeration callbacks. First you should package it and put it on marmalade (and melpa?) If you can do this perhaps the CPS style could just be integrated into the emacs-lisp interpreter/compiler? then yield could be implemented at a lower level? I'm personally uncomfortable about claiming `next'. At least use a better name, like `gen-next'? Perhaps it would be possible to avoid grabbing next by making it an argument to the object returned by yield: (defgenerator y (x) (while (> x 1) (setq x (- x 1)) (yield x))) (let ((g (y 10))) (funcall g :next) (funcall g :next) (funcall g :next)) => 7 The only thing nicer than that would be to have generators be real lisp-1 functions: (let ((g (y 10))) (g) (g) (g)) => 7 this would obviously be a lower level implementation of generators than some macros can provide. Other than that it's pretty neat stuff. Definitely this will be useful for implementing actors/CSP/go routines a la clojure core.async (and Go, of course).