[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RFC: rough draft of Python-style generators for elisp

From: Levin Du
Subject: Re: RFC: rough draft of Python-style generators for elisp
Date: Thu, 29 Nov 2012 16:41:29 +0800

Hi Daniel,

My Emacs version is "GNU Emacs".

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)
  call-interactively(ex-eval-region-or-sexp nil nil)

2012/11/28 Daniel Colascione <address@hidden>
On 11/27/12 9:31 AM, Burton Samograd wrote:
> Daniel Colascione <address@hidden> 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

Please let me know if you have any other problems.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]