Skip to content

main.aug ​

Modules and composition · 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.
import Console and SystemConsole from august.io
import Application and ApplicationImpl and Fruit and double and RangeError from domain
import Counter and Counters from counters
implement Console with SystemConsole
implement Application with ApplicationImpl
include Counters
resolve Application to app
app.start()
names to {1: "apple", 2: "pear"}
match names.get(key=2):
    when null:
        print(value="missing fruit")
    when some name:
        print(value=name)
(code, label) to (3, "plum")
print(
    value={Fruit(code=code, name=label), Fruit(name=label, code=code)}.length()
)
scope:
    resolve Counter to counter
    borrow counter:
        counter.increment()
    print(value=counter.value())
try:
    print(value=double(amount=7))
    double(amount=-1)
catch RangeError error:
    print(value="negative amount rejected")
aug
// aug-spec: "main.aug.md" explains this file. Read it before changes; refresh with aug spec.
import Console and SystemConsole from august.io
import Application and ApplicationImpl and Fruit and double and RangeError from domain
import Counter and Counters from counters
implement Console with SystemConsole
implement Application with ApplicationImpl
include Counters
resolve Application to app
app.start()
names to {1: "apple", 2: "pear"}
match names.get(key=2) {
    when null {
        print(value="missing fruit")
    }
    when some name {
        print(value=name)
    }
}
(code, label) to (3, "plum")
print(
    value={Fruit(code=code, name=label), Fruit(name=label, code=code)}.length()
)
scope {
    resolve Counter to counter
    borrow counter {
        counter.increment()
    }
    print(value=counter.value())
}
try {
    print(value=double(amount=7))
    double(amount=-1)
}
catch RangeError error {
    print(value="negative amount rejected")
}

Compiled specification ​

Interactions and sequences

Providers ​

Console is provided by SystemConsole. The same instance is shared.

Application is provided by ApplicationImpl. The same instance is shared. It requires bindings for Console. Include providers from Counters.

Startup ​

It sets app to the instance provided for Application. It calls app.start. It sets names to a map with 1 mapped to "apple"; 2 mapped to "pear". If the value under 2 in names is null, it prints "missing fruit". source

If the value under 2 in names is not null, using name for it prints name. It reads a tuple containing 3, "plum" once and binds [0] as code and [1] as label. It prints the number of elements in a set containing a Fruit with code and name from label, a Fruit with name from label and code. Within a task and ownership scope, it sets counter to the instance provided for Counter. source

With temporary permission to change counter, it calls counter.increment. It prints counter.value. On leaving this scope, join its child tasks and release its local values. It prints double with amount 7. source

It calls double with amount -1. If this work raises RangeError, it prints "negative amount rejected". source

Dependencies ​

It uses SystemConsole from august.io. It uses Counter (increment and value) and Counters from counters. It uses Application (start), ApplicationImpl, Fruit, RangeError, and double from domain.

Built-in operations follow the language reference.

Last updated:

The world runs on language