Created
December 21, 2023 10:57
-
-
Save Akeboshiwind/f55646c8e98793ec27af84506bd7969d to your computer and use it in GitHub Desktop.
Squint generators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; >> 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