Need help?
Ask a question or report a problem on GitHub.
Open an issue
Working with collections
Measure, order, search, and pick items from lists.
Collection Length
The same readable syntax works with collections:
Otter
say length of games
Example:
Otter
games are "Zelda" "Mario" "Pokemon" . say length of games
Output:
Output
3
First and Last
Otter
say first of games say last of games
Example:
Otter
say first of games say last of games
If the collection is empty:
Otter
say first of games
returns:
Output
gone
The same applies to:
Otter
say last of games
Reverse Collections
Otter
reverse games
This reverses the current order of the collection.
Find One Item
Otter uses find when the programmer wants one matching item.
Otter
find game in games where game is "Mario" into result
The first matching item is placed into result.
If nothing matches:
Otter
result is gone
This allows:
Otter
find game in games where game is "Mario" into result if result is gone say "Mario was not found." otherwise say "Found" result .
Find With Object Properties
find becomes especially useful with objects:
Otter
find file in files where extension of file is ".pdf" into result
Then:
Otter
if result is gone say "No PDF found." otherwise say "Found" name of result .
Derived Operations and Object Properties
Not every expression using of represents a stored property.
These are object properties:
Otter
say name of file say extension of file say age of person
These are operations:
Otter
say length of games say uppercase of name say first of games
They share readable surface grammar, but the parser may represent them differently internally.
The runtime object model should not pretend every derived operation is a stored property.