emacs-devel
[Top][All Lists]
Advanced

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

Re: RFC: Generators v2


From: Nic Ferrier
Subject: Re: RFC: Generators v2
Date: Sun, 25 Aug 2013 09:28:19 +0100

address@hidden 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).



reply via email to

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