Skip to content

Instantly share code, notes, and snippets.

@back2dos
Created June 1, 2015 07:57
Show Gist options
  • Select an option

  • Save back2dos/8f69fe87a5fa03c5709e to your computer and use it in GitHub Desktop.

Select an option

Save back2dos/8f69fe87a5fa03c5709e to your computer and use it in GitHub Desktop.
Macro context vs. output context
//Original source code:
class Main {
#if !macro
static function main() {
test();
}
#end
macro static function test() {
return makeHelloWorld();
}
#if macro
static function makeHelloWorld() {
return macro trace('hello world');
}
#end
}
//As seen from macro context
class Main {
macro static function test() {
return makeHelloWorld();
}
static function makeHelloWorld() {
return macro trace('hello world');
}
}
//As seen in the output context
class Main {
static function main() {
test();
}
macro static function test();
}
//After macro evaluation
class Main {
static function main() {
trace('hello world');//this is what was returned by Main.test() called in macro context
}
}
@back2dos

back2dos commented Jun 1, 2015

Copy link
Copy Markdown
Author

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