Objects and properties
An object groups named values. Create one with has, and read its properties with the everyday word of.
Otter
developer has
name is "Alice"
role is "Architect"
level is 3
.
say "Developer:" name of developer
say "Role:" role of developer
say "Level:" level of developer
Output
Developer: Alice
Role: Architect
Level: 3
Why of instead of a dot? In many languages the dot means decimals, method calls, namespaces, and property access all at once. In Otter the period has one meaning - finish a block - and properties are always property of object.
Changing a property
Otter
level of developer is 4
say "Updated level:" level of developer
Output
Updated level: 4
Custom types
Declare a type once with has, then create values of it:
Otter
a Person has
name
age
.
jeff is a Person with name "Jeff", age 29
say name of jeff
developer is a thing remains supported for older programs; has is the canonical form.
Next: files and folders