[Top][All Lists]

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

RFC: rough draft of Python-style generators for elisp

From: Daniel Colascione
Subject: RFC: rough draft of Python-style generators for elisp
Date: Mon, 26 Nov 2012 22:16:44 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:17.0) Gecko/17.0 Thunderbird/17.0

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.

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

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