3 ms·
I had so much fun playing with this. Here's the code I wrote for a simple scala-like for macro for { rule { {$x <- $y:expr;} {$z:expr} } => {
by santialbo 13y ago
I had so much fun playing with this. Here's the code I wrote for a simple scala-like for
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)
}