tact-lang / tact-vscode

Tact VS Code plugin
Apache License 2.0
22 stars 9 forks source link

Support conditional expressions (ternary operator) #26

Closed anton-trunov closed 9 months ago

anton-trunov commented 9 months ago

The dev version of Tact supports conditional expressions now: true ? 42 : 0. The relevant PR is here: https://github.com/tact-lang/tact/pull/97.

logvik commented 9 months ago

Can we create some Tact smart contract example's that will present all changes?

anton-trunov commented 9 months ago

sure, here you go:

contract Sample {

    init() { }

    // - octal and binary literals
    // - underscores in numerals
    // - augmented assignment operators (here only +=)
    // - conditional expression, a.k.a. ternary operator

    get fun foobar(a: Int): Int {
        let res: Int = 0;
        res +=
              (a == 1) ? 4_2
            : (a == 2) ? 0x2_B
            : (a == 3) ? 0o5_4
            : 0b101_101;
        return res;
    }
}
logvik commented 9 months ago

Added to v1.0.16