Created
September 27, 2013 21:47
-
-
Save disnet/6735679 to your computer and use it in GitHub Desktop.
hygiene
This file contains 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
var random = function(seed) { /* ... */ } | |
let m = macro { | |
rule {()} => { | |
var n = random(42); // ... | |
} | |
} |
In fact, instead of renaming macro-declared variables to prevent overlap, you could just wrap (while expanding) the body of the macro code in a stand-alone { .. }
block and change var
s to let
s, and that would create hygiene (aka, prevent any inner-to-outer leakage) in the same way as renaming, but with way less work.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@disnet
I suppose what I had in my mind was a mixture between the two. I was thinking a macro whose internal declarations were in fact hygenic (didn't leak out), but whose references to non-internal (aka, external) variables were not closured and instead just adopted the scope where they were expanded.
That model would prevent a macro that you use from accidentally overwriting something in your scope that is unexpected, but still let you provide in your own scope any other scoped bindings for any external references it may have.
To put it in the parlance of your post about variable renaming, you'd rename any variables that are declared inside a macro, but you wouldn't rename any other references which weren't declared there.
That would sort of turn
var
into alet
that bound itself to the scope of the macro's (implicit) block, while still letting in scope from outside the macro for external references.I can think of quite a few cases where I would use such a model.