Skip to content

counter.aug ​

Read access and mutable borrows · Source and specification

Files in this project

Code ​

aug
// aug-spec: "counter.aug.md" explains this file. Read it before changes; refresh with aug spec.
Counter(mutable int value) implements ICounter:
    increment():
        borrow self:
            value = value + 1
    read():
        return value
interface ICounter:
    increment() changes self
    read() returns int
aug
// aug-spec: "counter.aug.md" explains this file. Read it before changes; refresh with aug spec.
Counter(mutable int value) implements ICounter {
    increment() {
        borrow self {
            value = value + 1
        }
    }
    read() {
        return value
    }
}
interface ICounter {
    increment() changes self
    read() returns int
}

Compiled specification ​

Interactions and sequences

Counter · class · source ​

It implements ICounter. It takes value as an integer, kept mutable.

Counter.increment · source ​

It may change self. With temporary permission to change self, it increases value by 1. source

Checked interface
text
increment() returns void changes self

It may change self.

Counter.read · source ​

It returns value. source

Checked interface
text
read() returns int

ICounter · interface · source ​

ICounter.increment · source ​

It may change self.

ICounter.read · source ​

It returns int.

Last updated:

The world runs on language