Skip to content

Instantly share code, notes, and snippets.

@forestbelton
Last active August 29, 2015 14:01
Show Gist options
  • Save forestbelton/b9f40a91f4f18510e317 to your computer and use it in GitHub Desktop.
Save forestbelton/b9f40a91f4f18510e317 to your computer and use it in GitHub Desktop.
lazy evaluation with sweet.js
macro lazy {
rule { $e:expr } => {
new function() {
this.done = false;
this.valueOf = function() {
if(!this.done) {
this.done = true;
this.value = $e;
}
return this.value;
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment