Created
September 24, 2013 14:19
-
-
Save natefaubion/6685482 to your computer and use it in GitHub Desktop.
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 $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 |
What about using just rule
? The following fails to resolve to the same identifier also (just like above):
macro $testadd {
rule { $expr } => {
return $expr + test;
}
}
macro $wrap {
rule { $expr } => {
(function(test) {
$testadd 12
})($expr);
}
}
$wrap 42
Is it expected that it should resolve? It seems like it should, but that could be debatable.
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
Do you need to use
makeIdent
in$wrap
? If you just puttest
directly in as the parameter everything works out: