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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 oftest
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 oftest
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.