Skip to content

Instantly share code, notes, and snippets.

@joseoliv
Last active June 13, 2019 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joseoliv/9750202841204d509ba59c64ea34c3f1 to your computer and use it in GitHub Desktop.
Save joseoliv/9750202841204d509ba59c64ea34c3f1 to your computer and use it in GitHub Desktop.
init
package metaobjectTest
@doc{*
Annotation 'init' creates a method 'init:' based on a list
of fields to initialize
*}
object Init
func init {
max = 1000;
}
// ok, name and lastLetter receive values in their declarations
@init(max)
@init(name, lastLetter, max)
// compilation error if uncommented: max need to be initialized
// @init(name, lastLetter)
@init(name, max)
func run {
var p0 = Init(1000);
var p1 = Init new: "other", 'Z', 50;
var p2 = Init new: "other", 5000;
}
let String name = "init";
var Char lastLetter = 'z';
var Int max
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment