Skip to content

Instantly share code, notes, and snippets.

@gabro
Forked from utaal/iff.js
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabro/6314d6567bf66d6f2855 to your computer and use it in GitHub Desktop.
Save gabro/6314d6567bf66d6f2855 to your computer and use it in GitHub Desktop.
let if = macro {
rule {
($x:expr) {
$truebody
...
$truelast:expr
} else {
$falsebody
...
$falselast:expr
}
} => {
(function() {
var res = null;
if ($x) {
$truebody
...
res = $truelast;
} else {
$falsebody
...
res = $falselast
}
return res;
}())
}
}
var fortytwo = 42;
console.log(if(fortytwo == 42) {
var temp = fortytwo + 2;
"" + temp
} else {
null;
"not!"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment