[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Generators (iterators) for Gnu Emacs
From: |
David Kastrup |
Subject: |
Re: Generators (iterators) for Gnu Emacs |
Date: |
Fri, 05 Dec 2014 10:54:58 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) |
Stefan Monnier <address@hidden> writes:
>> (defmacro gen-make (&rest body)
>> "Return a generator that evaluates BODY to generate elements.
>> For each call of `gen-next' with the the returned generator, BODY
>> will be evaluated to produce an element."
>> (let ((this-element (make-symbol "this-element")))
>> `(let (,this-element)
>> (lambda ()
>
> AFAICT this requires lexical-binding in the caller, so we might want to
> signal an error if lexical-binding is nil.
Uh what? The whole point of the make-symbol abomination is to get a
symbol uniquely used by only one instance of the lambda function. This
is _exactly_ in order to _not_ require lexical binding.
>> (if (eq ,this-element 'gen-done)
>> 'gen-done
>> (setq ,this-element (progn ,@body)))))))
With lexical binding, this would look something like
(defmacro gen-mane (&rest body)
`(let (this-element)
(lambda ()
(if (eq this-element 'gen-done)
'gen-done
(setq this-element (progn ,@body))))))
And one would be tempted to see whether this really needs to be a macro.
--
David Kastrup
- Re: Generators (iterators) for Gnu Emacs, (continued)
- Re: Generators (iterators) for Gnu Emacs, Daniel Colascione, 2014/12/05
- Re: Generators (iterators) for Gnu Emacs, Daniel Colascione, 2014/12/05
- Re: Generators (iterators) for Gnu Emacs, Daniel Colascione, 2014/12/05
- Re: Generators (iterators) for Gnu Emacs, Daniel Colascione, 2014/12/05
- Re: Generators (iterators) for Gnu Emacs, Daniel Colascione, 2014/12/05
- Re: Generators (iterators) for Gnu Emacs, Daniel Colascione, 2014/12/05
- Re: Generators (iterators) for Gnu Emacs, Stephen J. Turnbull, 2014/12/06
- Re: Generators (iterators) for Gnu Emacs, Daniel Colascione, 2014/12/05
- Re: Generators (iterators) for Gnu Emacs, Daniel Colascione, 2014/12/05
- Re: Generators (iterators) for Gnu Emacs, Daniel Colascione, 2014/12/05
Re: Generators (iterators) for Gnu Emacs,
David Kastrup <=
- Re: Generators (iterators) for Gnu Emacs, Stefan Monnier, 2014/12/05
- Re: Generators (iterators) for Gnu Emacs, Michael Heerdegen, 2014/12/05
- Re: Generators (iterators) for Gnu Emacs, Stefan Monnier, 2014/12/05
- Re: Generators (iterators) for Gnu Emacs, Michael Heerdegen, 2014/12/05
- Re: Generators (iterators) for Gnu Emacs, Stefan Monnier, 2014/12/05
Re: Generators (iterators) for Gnu Emacs, Michael Heerdegen, 2014/12/05
Re: Generators (iterators) for Gnu Emacs, Thierry Volpiatto, 2014/12/05