From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Levin Du Newsgroups: gmane.emacs.devel Subject: Re: RFC: rough draft of Python-style generators for elisp Date: Thu, 29 Nov 2012 16:41:29 +0800 Message-ID: References: <50B4309C.5000109@dancol.org> <50B5300A.4060600@dancol.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=f46d040711e5d47a2404cf9e3f96 X-Trace: ger.gmane.org 1354178510 16054 80.91.229.3 (29 Nov 2012 08:41:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 29 Nov 2012 08:41:50 +0000 (UTC) Cc: Burton Samograd , emacs-devel@gnu.org To: Daniel Colascione Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Nov 29 09:42:00 2012 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 1Tdzgw-0007JT-VW for ged-emacs-devel@m.gmane.org; Thu, 29 Nov 2012 09:41:55 +0100 Original-Received: from localhost ([::1]:40500 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tdzgl-0001LB-MS for ged-emacs-devel@m.gmane.org; Thu, 29 Nov 2012 03:41:43 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:54365) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tdzgg-0001L3-2D for emacs-devel@gnu.org; Thu, 29 Nov 2012 03:41:42 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TdzgZ-0002TD-Lg for emacs-devel@gnu.org; Thu, 29 Nov 2012 03:41:37 -0500 Original-Received: from mail-lb0-f169.google.com ([209.85.217.169]:52196) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TdzgZ-0002Sz-9R for emacs-devel@gnu.org; Thu, 29 Nov 2012 03:41:31 -0500 Original-Received: by mail-lb0-f169.google.com with SMTP id gk1so12574458lbb.0 for ; Thu, 29 Nov 2012 00:41:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=C69vwhjD/4IOrNTZ8q77DoeZN8dd5SKgzYB6XszybHE=; b=HssPnN4La4ehOptcg26n/0kD7iIFplE3zpnWHWR9QmYKXPSLJqrD7Y3+RQzocP72Vv Ybd7cHejh7ro75NOO3u9dHm8BWTa/TDL0L2cFczY+BR/GN0pZNIL9hji26gBoNwtOzq6 qZ6WnQd3KC4B4VYgOkjnSQAvuPXstTDxOwu35dGoWFc0SYkTM1LWWFYKSHb4tm9N2fi2 SOXoIqVxiQ+jj5iUE0SRBuSih5wp7fzPmxH7Ok/H2fdJZhTwlqG60h85T3CBdFmSrPGG pUmsSxO8SDHoYpoeIB+hKO1tA2xXvRnaJM39APxRIMX9p30ZemrvRDG+89nnk0E9dMsh v3ZQ== Original-Received: by 10.152.103.100 with SMTP id fv4mr20546321lab.39.1354178489514; Thu, 29 Nov 2012 00:41:29 -0800 (PST) Original-Received: by 10.152.121.35 with HTTP; Thu, 29 Nov 2012 00:41:29 -0800 (PST) In-Reply-To: <50B5300A.4060600@dancol.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.217.169 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:155121 Archived-At: --f46d040711e5d47a2404cf9e3f96 Content-Type: text/plain; charset=ISO-8859-1 Hi Daniel, My Emacs version is "GNU Emacs 24.3.50.1". I tried: (defgenerator mygen (i) (yield 1) (yield i) (yield 3)) (let ((gen (mygen 100))) (list (funcall gen) (funcall gen) (funcall gen))) but failed with: Debugger entered--Lisp error: (void-variable cps-current-state-91642) (funcall cps-current-state-91642) (while t (funcall cps-current-state-91642)) (catch (quote cps-yield) (while t (funcall cps-current-state-91642))) (lambda nil (catch (quote cps-yield) (while t (funcall cps-current-state-91642))))() funcall((lambda nil (catch (quote cps-yield) (while t (funcall cps-current-state-91642))))) (list (funcall gen) (funcall gen) (funcall gen)) (let ((gen (mygen 100))) (list (funcall gen) (funcall gen) (funcall gen))) eval((let ((gen (mygen 100))) (list (funcall gen) (funcall gen) (funcall gen))) nil) eval-last-sexp-1(nil) eval-last-sexp(nil) call-interactively(eval-last-sexp) ex-eval-region-or-sexp() call-interactively(ex-eval-region-or-sexp nil nil) 2012/11/28 Daniel Colascione > On 11/27/12 9:31 AM, Burton Samograd wrote: > > Daniel Colascione writes: > > > >> Over at https://github.com/dcolascione/elisp-generators, I have a > >> pure-elisp implementation of Python-style generators for elisp. > >> Perhaps the feature is best illustrate by example: > >> > >> (defgenerator mygen (i) > >> (yield 1) > >> (yield i) > >> (yield 3)) > >> > >> (let ((gen (mygen 100))) > >> (list (funcall gen) > >> (funcall gen) > >> (funcall gen))) > >> > >> -> (1 100 3) > >> > >> Yields can appear in arbitrary code: > >> > >> (defgenerator mygen2 (lim) > >> (loop for x from 0 to lim do (yield x))) > >> > >> The package works by rewriting elisp into continuation-passing form > >> and closing over the resulting continuations with a driver loop that > >> transitions from one continuation-state to the next. After the last > >> yield, the facility signals generator-ended. > >> > >> Please take a look. It'd be nice if there were cl-loop extensions to > >> iterate over the things, and if generators were available with regular > >> defun the way yield is available with regular "def" in Python. > > > > When I try and byte-compile your package I get the following: > > Thanks for trying the package. I've updated it to use pcase, and I > fixed the compilation issues by side effect. A few warnings about > unused lexical variables remain, but I'm convinced these warnings are > spurious. > > Please let me know if you have any other problems. > > --f46d040711e5d47a2404cf9e3f96 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi Daniel,

My Emacs version is "GNU Emac= s 24.3.50.1".

I tried:

(defgene= rator mygen (i)
=A0 (yield 1)
=A0 (yield i)
=A0 (yield 3))<= /span>

(let ((gen (mygen 100)))
=A0 (list =A0(f= uncall gen)
=A0 =A0 =A0 = =A0 =A0(funcall gen)
=A0 =A0 =A0 =A0= =A0(funcall gen)))

but failed with:

Debugger entered--Lisp error: (void-variable cps-curren= t-state-91642)
=A0 (funcall cps-current-state-91642)
= =A0 (while t (funcall cps-current-state-91642))
=A0 (catch (quote= cps-yield) (while t (funcall cps-current-state-91642)))
=A0 (lambda nil (catch (quote cps-yield) (while t (funcall cps-current= -state-91642))))()
=A0 funcall((lambda nil (catch (quote cps-yiel= d) (while t (funcall cps-current-state-91642)))))
=A0 (list (func= all gen) (funcall gen) (funcall gen))
=A0 (let ((gen (mygen 100))) (list (funcall gen) (funcall gen) (funcal= l gen)))
=A0 eval((let ((gen (mygen 100))) (list (funcall gen) (f= uncall gen) (funcall gen))) nil)
=A0 eval-last-sexp-1(nil)
<= div> =A0 eval-last-sexp(nil)
=A0 call-interactively(eval-last-sexp)
=A0 ex-eval-region-or-sexp()
=A0 call-interactively(ex-ev= al-region-or-sexp nil nil)

<= br>
2012/11/28 Daniel Colascione &= lt;dancol@dancol.org= >
On 11/27/12 9:31 AM, Burton Samograd wrote:
> Daniel Colascione <dancol@dancol.org> writes:
>
>> Over at https://github.com/dcolascione/elisp-generators, I = have a
>> pure-elisp implementation of Python-style generators for elisp. >> Perhaps the feature is best illustrate by example:
>>
>> (defgenerator mygen (i)
>> =A0 (yield 1)
>> =A0 (yield i)
>> =A0 (yield 3))
>>
>> (let ((gen (mygen 100)))
>> =A0 (list =A0(funcall gen)
>> =A0 =A0 =A0 =A0 =A0(funcall gen)
>> =A0 =A0 =A0 =A0 =A0(funcall gen)))
>>
>> -> (1 100 3)
>>
>> Yields can appear in arbitrary code:
>>
>> (defgenerator mygen2 (lim)
>> =A0 (loop for x from 0 to lim do (yield x)))
>>
>> The package works by rewriting elisp into continuation-passing for= m
>> and closing over the resulting continuations with a driver loop th= at
>> transitions from one continuation-state to the next. After the las= t
>> yield, the facility signals generator-ended.
>>
>> Please take a look. It'd be nice if there were cl-loop extensi= ons to
>> iterate over the things, and if generators were available with reg= ular
>> defun the way yield is available with regular "def" in P= ython.
>
> When I try and byte-compile your package I get the following:

Thanks for trying the p= ackage. I've updated it to use pcase, and I
fixed the compilation issues by side effect. A few warnings about
unused lexical variables remain, but I'm convinced these warnings are spurious.

Please let me know if you have any other problems.


--f46d040711e5d47a2404cf9e3f96--