Skip to content

Instantly share code, notes, and snippets.

@Akeboshiwind
Created December 21, 2023 10:57
Show Gist options
  • Save Akeboshiwind/f55646c8e98793ec27af84506bd7969d to your computer and use it in GitHub Desktop.
Save Akeboshiwind/f55646c8e98793ec27af84506bd7969d to your computer and use it in GitHub Desktop.
Squint generators
;; >> No errors
;; Works as expected
(defn ^:gen foo []
(js-yield 1)
(js-yield* [2 3])
(let [x (do (js-yield 4)
5)]
(js-yield x)))
function* foo () {
yield 1;
yield* [2, 3];
let x = undefined;
yield* (function* () {
yield 4;
x = 5;
})();
yield x;
}
;; >> Wrap `let`
;; Works as expected
(defn ^:gen foo []
(js-yield 1)
(js-yield* [2 3])
(try
(let [x (do (js-yield 4)
(throw "error")
5)]
(js-yield x))
(catch Exception e
(js-yield 6))))
function* foo () {
yield 1;
yield* [2, 3];
try {
let x = undefined;
yield* (function* () {
yield 4;
throw "error";
x = 5;
})();
yield x;
} catch (e) {
yield 6
}
}
;; Wrap `do`
;; Ends up with `x` as `undefined`
(defn ^:gen foo []
(js-yield 1)
(js-yield* [2 3])
(let [x (try
(do (js-yield 4)
(throw "error")
5)
(catch Exception e
(js-yield 6)))]
(js-yield x)))
function* foo () {
yield 1;
yield* [2, 3];
let x = undefined;
try {
yield* (function* () {
yield 4;
throw "error";
x = 5;
})();
} catch (e) {
yield 6
}
yield x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment