Skip to content

Instantly share code, notes, and snippets.

@disnet
Created September 27, 2013 21:47
Show Gist options
  • Save disnet/6735679 to your computer and use it in GitHub Desktop.
Save disnet/6735679 to your computer and use it in GitHub Desktop.
hygiene
var random = function(seed) { /* ... */ }
let m = macro {
rule {()} => {
var n = random(42); // ...
}
}
@getify
Copy link

getify commented Sep 30, 2013

@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 a let 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.

@getify
Copy link

getify commented Oct 1, 2013

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 vars to lets, 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