main.aug
Lists, tuples, sets, and maps · Source and specification
Files in this project
Code
aug
// aug-spec: "main.aug.md" explains this file. Read it before changes; refresh with aug spec.
try:
numbers = List<int>(2, 4)
borrow numbers:
numbers.append(value=6)
print(value=numbers.length())
print(value=numbers.get(index=1))
scores = Map<string, int>()
borrow scores:
scores.set(value=42, key="ada")
print(value=scores.contains(key="ada"))
print(value=scores.get(key="ada"))
print(value=scores.length())
catch IndexError error:
print(value="unexpected index failure")aug
// aug-spec: "main.aug.md" explains this file. Read it before changes; refresh with aug spec.
try {
numbers = List<int>(2, 4)
borrow numbers {
numbers.append(value=6)
}
print(value=numbers.length())
print(value=numbers.get(index=1))
scores = Map<string, int>()
borrow scores {
scores.set(value=42, key="ada")
}
print(value=scores.contains(key="ada"))
print(value=scores.get(key="ada"))
print(value=scores.length())
}
catch IndexError error {
print(value="unexpected index failure")
}Compiled specification
Startup
It sets numbers to a list of int containing 2, 4. With temporary permission to change numbers, it appends 6 to numbers. It prints the number of elements in numbers. It prints the item at index 1 in numbers. source
It sets scores to an empty map from string to int. With temporary permission to change scores, it stores 42 in scores under "ada". It prints whether scores contains the key "ada". It prints the value under "ada" in scores. source
It prints the number of elements in scores. If this work raises IndexError, it prints "unexpected index failure". source
Built-in operations follow the language reference.