I found sweet.js so much useful for scraping boilerplate out of my code. Example — sweet-assertions <a href="https://github.com/andreypopp/sweet-assertions" rel="nofollow">https://github.com/andreypopp/sweet-assertions</a> — a set of macros to generate assertions with nice failure messages.<p>Edit: another experimental macros — <a href="https://github.com/andreypopp/react-macros" rel="nofollow">https://github.com/andreypopp/react-macros</a> — a set of syntax extensions for writing React (<a href="http://facebook.github.io/react" rel="nofollow">http://facebook.github.io/react</a>) components.
I tried a simple one. Here is my interpretation of Scheme's delay/force macros: <a href="https://www.refheap.com/36606" rel="nofollow">https://www.refheap.com/36606</a> (forgive the messed up indentation...)
I had so much fun playing with this. Here's the code I wrote for a simple scala-like for<p><pre><code> macro for {
rule { {$x <- $y:expr;} {$z:expr} } => {
$y.forEach(function($x) { $z });
}
rule { {$x <- $y:expr; $($a <- $b:expr) (;) ... } {$z:expr} } => {
$y.forEach(function($x) {
for { $($a <- $b;) ... } {
$z
}
})
}
}
for {
i <- [1,2,3];
j <- [3,2,1];
k <- [5,5,5];
} {
console.log(i + j + k)
}</code></pre>
The interactive macro editor is a great touch. I don't know if this is prevalent, but this is the first time I've seen a tutorial interactively modify code in the editor <i>for you</i>. Instead of "here, type this into the editor above and see what happens," there will be a link to "click here to see what happens" and it will change the code in the editor accordingly. I think this is a good thing, because I rarely go and do the things that tutorials suggest I do, even if they are as simple as typing into an editor that is 2 inches above the text I am reading.