Skip to content

Instantly share code, notes, and snippets.

@joseoliv joseoliv/InsertCode
Created Jun 14, 2019

Embed
What would you like to do?
insertCode
package metaobjectTest
@doc{*
Annotation 'insertCode'
*}
object InsertCode
@insertCode{*
var Int n = 0;
for elem in [ "red", "green", "blue" ] {
var String s = " func " ++ elem ++ " -> Int; ";
insert: s, " func " ++ elem ++ " -> Int = " ++ n ++ ";" ++ '\n';
n = n + 1
}
*}
func run {
assert red == 0 && green == 1 && blue == 2;
var Int fat12;
@insertCode{*
var p = 2;
for n in 3..12 {
p = p*n
}
insert: " fat12 = " ++ p ++ ";" ++ '\n';
*}
"The factorial of 12 is $fat12" println;
@insertCode{*
// print values returned by methods red, green, and blue
for elem in [ "red", "green", "blue" ] {
insert: "self " ++ elem ++ " println;" ++ '\n';
}
*}
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.