Skip to content

Instantly share code, notes, and snippets.

@natefaubion
Created September 24, 2013 14:19
Show Gist options
  • Save natefaubion/6685482 to your computer and use it in GitHub Desktop.
Save natefaubion/6685482 to your computer and use it in GitHub Desktop.
macro $testadd {
case { $$mac $expr } => {
var ident = makeIdent('test', #{ $$mac });
return withSyntax ($ident = [ident]) {
return #{
return $expr + $ident;
}
}
}
}
macro $wrap {
case { $$mac $expr } => {
var ident = makeIdent('test', #{ $$mac });
return withSyntax ($ident = [ident]) {
return #{
(function($ident) {
$testadd 12
})($expr);
}
}
}
}
$wrap 42
@disnet
Copy link

disnet commented Sep 24, 2013

Yep, it makes perfect sense for rule to behave this way, it's just preserving hygiene. Just think of hygiene as preserving lexical scope. To find the binding of test inside $testadd all you should do is look at the scope at the definition of $testadd (not at the use of $testadd). Since there is no binding of test at the definition then we assume it's either unbound or bound as a global (and so don't perform any renaming).

If we were to bind the test introduced by expanding $testadd 12 to the binding in the IIFE this would be breaking hygiene.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment