Created
April 26, 2014 16:53
-
-
Save fakenickels/11325001 to your computer and use it in GitHub Desktop.
Swap macro with 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 swap { | |
rule { $x and $y } => { | |
var tmp = $x; | |
$x = $y; | |
$y = tmp | |
} | |
} | |
// Let's go! | |
var a = "a", | |
b = "b"; | |
console.log(a, b); // => a b | |
// And here the magic happens :3 | |
swap a and b; | |
console.log(a, b); // b a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment