Skip to content

Instantly share code, notes, and snippets.

@utaal

utaal/iff.js

Created Dec 29, 2014
Embed
What would you like to do?
sweet.js if expression macro
macro iff {
rule {
($x:expr) {
$truebody
...
$truelast:expr
} els {
$falsebody
...
$falselast:expr
}
} => {
(function() {
var res = null;
if ($x) {
$truebody
...
res = $truelast;
} else {
$falsebody
...
res = $falselast
}
return res;
}())
}
}
var fortytwo = 42;
console.log(iff(fortytwo == 42) {
var temp = fortytwo + 2;
"" + temp
} els {
null;
"not!"
});
@utaal

This comment has been minimized.

Copy link
Owner Author

@utaal utaal commented Dec 29, 2014

Prints

44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.