Guide Index Previous Part Next Part Download Markdown

#Part 2. CBP Language

#Part 2 Section 1. Minimal Program

A CBP program normally starts at fn main(). Library imports go above it. Semicolons are optional at the end of a line, but braces are not optional.

library CB-Console

fn main() {
    u256 coins = 1_000_000 + 250_000
    println("Coins:", coins)
    save coins
}

That example prints a number and saves it as the package result. It is small enough to check, build, and inspect.

#Part 2 Section 2. Types

Use explicit types when the value matters. ClosedBit supports checked unsigned integers, checked signed integers, floats, booleans, strings, and arrays.

u256 score = 0
i256 debt = -42
f128 cameraX = 12.5
bool alive = true
string name = "Player"
array items = ["key", "map"]

Do not widen everything by habit. Start with the smallest type that is safe for the value, then widen when the app has a real reason.

#Part 2 Section 3. Math And Flow

CBP uses normal arithmetic precedence. Multiplication and division happen before addition and subtraction, and parentheses are accepted.

u256 a = 5 + 7 * 3      # 26
u256 b = (5 + 7) * 3    # 36

Use if, else, while, and for for ordinary logic. Reserve bitwise operators for actual bit work.

fn main() {
    u256 ammo = 12

    if (ammo > 0) {
        println("Ready")
    } else {
        println("Reload")
    }
}

#Part 2 Section 4. Overflow And Fallbacks

ClosedBit checks arithmetic instead of silently wrapping. If a value cannot fit, the runtime reports it. That is useful, but an app still needs recovery paths around user input, division, square roots, indexing, and file reads.

library CB-Math

fn main() {
    string raw = input("Amount: ")
    u256 amount = parse_u256_or(raw, 0)
    f64 safeRoot = math.sqrt_or(-5, 0)
    println(amount, safeRoot)
}

Use _or helpers when bad data should fall back. Use try and catch when you need to recover from a block that may fail.