Open thehydroimpulse opened 10 years ago
Sure, I'd love a pull request. Note that currently generators will actually work in spidermonkey:
(fn []
(yield 1)
(yield 2))
This will output:
function() {
yield(1);
return yield(2);
}
I'd suggest to add support via metadata so that syntax sugar can be just a macro:
(defmacro generator
[& forms]
(with-meta (cons 'fn forms) {:generator true}))
(generator []
(yield 1)
(yield 2))
And then modify writer to such that it will set :generator
to (:generator (meta form))
Although the problem is I don't think escodegen used to generate JS form AST supports generators yet, so that will require fixing too.
@Gozala Awesome. Right now Node also supports generators under the --harmony
or --harmony-generator
flag (>=0.11.4). Hopefully it'll become stable soon, which then the flags will be on by default.
@TheHydroImpulse Forgot to put link to a writer I was intending to, updated my comment to include it now.
What do you think of supporting harmony generators?
I'd send in a PR if you'd like.