-
-
Save vendethiel/8230304 to your computer and use it in GitHub Desktop.
do.sjs fixed for new sweet.js
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
macro $do { | |
rule { { $y:expr } } => { | |
$y | |
} | |
rule { { $x:ident <- $y:expr $rest ... } } => { | |
λ['>=']($y, function($x) { | |
return $do { $rest ... } | |
}); | |
} | |
} | |
// Using the bilby.js functional programming library: | |
// https://github.com/pufuwozu/bilby.js | |
var λ = require('./bilby'); | |
// Haskell: | |
// | |
// do | |
// x <- [1, 2] | |
// y <- [x, x] | |
// [y * 2, y * 3] | |
// | |
// [2,3,2,3,4,6,4,6] | |
// sweet.js: | |
// Can't use arrays directly because of https://github.com/mozilla/sweet.js/issues/28 | |
// Need to manually replace a, b and c in output with array expressions. | |
var list = $do { | |
x <- [1, 2] | |
y <- [x, x] | |
c // [y * 2, y * 3] | |
}; | |
console.log(list); | |
// [ 2, 3, 2, 3, 4, 6, 4, 6 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment