Unnatural version which is like the other languages.
names := list(
Map clone atPut("first", "Bob") atPut("given", "Smith"),
Map clone atPut("given", "Lukas"),
Map clone atPut("first", "Mary") atPut("given", "Doe")
)
printName := method(name,
writeln("Name is ", name at("first"), " ", name at("given"))
)
names foreach(name,
printName(name)
)
Natural Io version of the code.
Name := Object clone do(
newSlot("first")
newSlot("given")
printName := method(
writeln("Name is ", first, " ", given)
)
)
names := list(
Name clone setFirst("Bob") setGiven("Smith"),
Name clone setGiven("Lukas"),
Name clone setFirst("Mary") setGiven("Doe")
)
names foreach(printName)
Both versions run without error or warnings and produce the following output.
Name is Bob Smith
Name is nil Lukas
Name is Mary Doe