Skip to main content Svelte Highlight v7.21.1

C3 language preview

1. A counter struct

compile-time directives, optional types, and nextcase
horizon-dark
module counters;

fn int increment(int x) {
    $if $defined(x):
        return x + 1;
    $endif
    return x;
}

struct Counter {
    int value;
    String? name;
}

fn void main() {
    Counter c = { .value = 0 };
    switch (c.value) {
        case 0:
            nextcase default;
        default:
            io::printn("done");
    }
}
atom-one-dark
module counters;

fn int increment(int x) {
    $if $defined(x):
        return x + 1;
    $endif
    return x;
}

struct Counter {
    int value;
    String? name;
}

fn void main() {
    Counter c = { .value = 0 };
    switch (c.value) {
        case 0:
            nextcase default;
        default:
            io::printn("done");
    }
}
github-dark
module counters;

fn int increment(int x) {
    $if $defined(x):
        return x + 1;
    $endif
    return x;
}

struct Counter {
    int value;
    String? name;
}

fn void main() {
    Counter c = { .value = 0 };
    switch (c.value) {
        case 0:
            nextcase default;
        default:
            io::printn("done");
    }
}
dracula
module counters;

fn int increment(int x) {
    $if $defined(x):
        return x + 1;
    $endif
    return x;
}

struct Counter {
    int value;
    String? name;
}

fn void main() {
    Counter c = { .value = 0 };
    switch (c.value) {
        case 0:
            nextcase default;
        default:
            io::printn("done");
    }
}
nord
module counters;

fn int increment(int x) {
    $if $defined(x):
        return x + 1;
    $endif
    return x;
}

struct Counter {
    int value;
    String? name;
}

fn void main() {
    Counter c = { .value = 0 };
    switch (c.value) {
        case 0:
            nextcase default;
        default:
            io::printn("done");
    }
}
github
module counters;

fn int increment(int x) {
    $if $defined(x):
        return x + 1;
    $endif
    return x;
}

struct Counter {
    int value;
    String? name;
}

fn void main() {
    Counter c = { .value = 0 };
    switch (c.value) {
        case 0:
            nextcase default;
        default:
            io::printn("done");
    }
}

2. Attributes

@extern, @packed, and @test
horizon-dark
@extern fn void raw_syscall(int n);

@packed
struct Header {
    char magic;
    int length;
}

@test
fn void test_increment() {
    assert(increment(1) == 2);
}
atom-one-dark
@extern fn void raw_syscall(int n);

@packed
struct Header {
    char magic;
    int length;
}

@test
fn void test_increment() {
    assert(increment(1) == 2);
}
github-dark
@extern fn void raw_syscall(int n);

@packed
struct Header {
    char magic;
    int length;
}

@test
fn void test_increment() {
    assert(increment(1) == 2);
}
dracula
@extern fn void raw_syscall(int n);

@packed
struct Header {
    char magic;
    int length;
}

@test
fn void test_increment() {
    assert(increment(1) == 2);
}
nord
@extern fn void raw_syscall(int n);

@packed
struct Header {
    char magic;
    int length;
}

@test
fn void test_increment() {
    assert(increment(1) == 2);
}
github
@extern fn void raw_syscall(int n);

@packed
struct Header {
    char magic;
    int length;
}

@test
fn void test_increment() {
    assert(increment(1) == 2);
}

3. Error handling

the ! rethrow and ?? default operators
horizon-dark
fn void! risky() {
    return foo()!;
}

fn int safe() {
    return risky() ?? -1;
}
atom-one-dark
fn void! risky() {
    return foo()!;
}

fn int safe() {
    return risky() ?? -1;
}
github-dark
fn void! risky() {
    return foo()!;
}

fn int safe() {
    return risky() ?? -1;
}
dracula
fn void! risky() {
    return foo()!;
}

fn int safe() {
    return risky() ?? -1;
}
nord
fn void! risky() {
    return foo()!;
}

fn int safe() {
    return risky() ?? -1;
}
github
fn void! risky() {
    return foo()!;
}

fn int safe() {
    return risky() ?? -1;
}