A Person record and a program that uses it
The complete source of structure_person.ek9, compiled by the EK9 compiler. Shown on structure.html.
#!ek9 defines module site.structure.person defines record Person first as String: String() last <- String() dob <- Date() profession <- String() override operator ? as pure <- rtn as Boolean: first? and last? and dob? and profession? operator $ as pure <- rtn as String: `${first}, ${last}, ${dob}, ${profession}` operator == as pure -> other as Person <- rtn as Boolean: other? and first == other.first and last == other.last and dob == other.dob operator #? as pure <- rtn as Integer: #? first + #? last + #? dob defines program InferenceExample() smithj <- Person() //Different ways of assigning value smithj.first: "John" smithj.last := "Smith" smithj.dob = 1960-01-01 smithj.profession: "IT" firstName <- smithj.first Stdout().println(`${firstName} - ${smithj}`)
Output
John - John, Smith, 1960-01-01, IT