OTTER 1.0.1 · QUICK REFERENCE
Everything you need to start building with Otter.
The whole language on one page. Print it, keep it next to your keyboard, and look things up as you go. Every example was run with Otter 1.0.1.
The Otter mascot
Otter 1.0.1 Quick Reference · otterprogramming.com
1. Run a program
otter hello.ot # run it otter # try lines otter check hello.ot # check only otter web app.ot # web page otter new console myapp # new project
Otter files end in .ot. Running from the downloaded folder on Windows? Use .\otter.cmd hello.ot instead.
2. Values
name is "Ada" # text age is 36 # number price is 9.99 ready is true # true or false nickname is gone # no value at all
is gives a name a value. Text goes in double quotes. Everything after # is a comment.
3. Say and ask
say "Hello," name # Hello, Ada say "Saved" in color "green" ask "How old are you?" and call it age
say puts one space between its parts. ask turns 29 into a number and true into a boolean; anything else stays text.
4. Math
5 and 3 make total # 8 10 minus 4 make left # 6 6 times 7 make answer # 42 20 divided by 4 make share # 5 sum is 5 plus 3 # 8 add 1 to score remove 2 from score
Math uses words, not symbols. add and remove change a number in place. Dividing by zero is a clear Otter error.
5. Text
say length of name # 3 say uppercase of name # ADA say lowercase of name # ada split "red,green,blue" by "," into colors join colors with " | " into line say "one\ttwo" # \t is a tab say "line\nbreak" # \n is a new line say "She said \"hi\""
Check text with starts with, ends with and contains (see the comparison words).
6. Decisions
if age is at least 18 say "Adult" otherwise if age is at least 13 say "Teen" otherwise say "Child" .
Indent the inside of a block. A period on its own line ends it.
7. Comparison words
is equal to is not not equal to is greater than > is less than < is at least >= is at most <= contains list has it / text has it starts with text begins with ends with text ends with is gone has no value
Join conditions with and / or: if age is greater than 30 and ready
8. Loops
repeat 3 times say "Hooray!" . count from 1 to 5 as n say n . each game in games say "I like" game . while tries is less than 3 add 1 to tries .
9. Lists
games are "Zelda" "Mario" . add "Pokemon" to games remove "Mario" from games say length of games # 2 say first of games # Zelda say last of games # Pokemon random item from games into pick
say games prints Zelda, Pokemon. add and remove work on lists as well as numbers.
10. Functions
to greet person say "Hello," person . greet "Grace" to tax subtotal and rate subtotal times rate make amount return amount . tax 100 and 0.08 make owed # 8 due is tax 200 and 0.05 # 10
Separate inputs with and. A function's names are its own: they never change the ones outside it.
11. Objects
pet has name is "Pip" age is 3 . say name of pet # Pip age of pet is 4 a Person has name age . grace is a Person with name "Grace", age 85
Read a property with of: name of pet. Otter never uses pet.name.
12. When something fails
try read "notes.txt" into notes otherwise say "Could not read the file." .
Without try, Otter stops and explains: the line, what went wrong, and a fix to try.
Line 1: say length of games Otter could not find the variable "games". Try: games is 0
13. Files and folders
write "first line" to "notes.txt" append "more" to "notes.txt" read "notes.txt" into notes if file "notes.txt" exists say notes . copy "notes.txt" to "backup.txt" delete file "backup.txt" get files in "." into found
append adds the text exactly as given; put \n at the start for a new line. Each found file has a name, extension and size.
14. JSON, dates and random
read json from "settings.json" into settings say theme of settings convert text from json into data day is today moment is now add 7 days to day format day as "yyyy-MM-dd" into stamp random number from 1 to 6 into roll
JSON becomes ordinary Otter objects and lists. today has no time of day; now has both.
15. A desktop window
clicks is 0 create window into app title of app is "Counter" create text into display text of display is "0" create button into addButton text of addButton is "Add one" put display in app put addButton in app when addButton is clicked increase clicks text of display is clicks . show app
Run it with otter counter.ot. Controls include text, text box, button, row, column, card, grid and scroll.
16. A web page
app is a page with title "Greeter", width 560, spacing 14 nameBox is a text box with placeholder "Your name" helloButton is a button with text "Say hello" message is a text with value "Waiting..." when helloButton is clicked text of message is text of nameBox . put nameBox, helloButton, message in app show app
otter web greeter.ot turns it into a standalone web page and opens it.
17. Rules of thumb
• is gives a value. Otter has no = sign.
• Indent the inside of a block; a period on its own line ends it.
• Properties read name of person, never person.name.
• Using a name before giving it a value is an error, not false.
• A few words, such as count, are statement words and cannot be names. Otter tells you if you try.
• Stuck? Read the error: it names the line and suggests a fix.