A record's string conversion by interpolation
The complete source of standardTypes_record_string.ek9, compiled by the EK9 compiler. Shown on standardTypes.html.
#!ek9 defines module site.standardtypes.recordstring defines record CustomerRecord id <- String() firstName <- String() lastName <- String() email <- String() dob <- String() lastPurchase <- String() default CustomerRecord() as pure CustomerRecord() as pure -> id as String firstName as String lastName as String email as String dob as String lastPurchase as String this.id :=? String(id) this.firstName :=? String(firstName) this.lastName :=? String(lastName) this.email :=? String(email) this.dob :=? String(dob) this.lastPurchase :=? String(lastPurchase) override operator ? as pure <- rtn as Boolean: id? operator $ as pure <- rtn as String: String() rtn := `${id}, ${firstName}, ${lastName}, ${email}, ${dob}, ${lastPurchase}` defines program RecordString() stdout <- Stdout() customer <- CustomerRecord(id: "1", firstName: "Steve", lastName: "Limb", email: "a@b.com", dob: "1960-01-01", lastPurchase: "2020-01-01") stdout.println($customer)
Download standardTypes_record_string.ek9
Output
1, Steve, Limb, a@b.com, 1960-01-01, 2020-01-01