Skip to content

Control Flow and Schedule

Culsma supports loops, conditionals, and schedule-driven repetition.

Fixed Repetition

text
repeat 3 {
    target << [source:5uL];
}

The expression must be decidable for the repeat count.

Repeat counts may come from protocol parameters when they can be resolved while the plan is built:

text
protocol Wash(cycles = 3) {
    repeat cycles {
        target << [buffer:5uL];
    }
}

Schedule Repetition

text
repeat point in schedule(start = 30min, end = 120min, step = 30min) {
    let obs = phy(sample = reactor, quantity = temperature);
}

Inside the loop, point is bound to the current checkpoint value.

Schedule boundaries may also be parameterized:

text
protocol Observe(cycles = 35) {
    repeat cycle in schedule(start = 1, end = cycles, step = 1) {
        let obs = phy(sample = reactor, quantity = temperature);
    }
}

Discrete Schedule Forms

Use start, end, and step:

text
schedule(start = 1, end = 35, step = 1)
schedule(start = 30min, end = 120min, step = 30min)

Or use explicit checkpoints:

text
schedule(at = [15min, 45min, 120min])

The two forms are alternatives. Do not mix at=[...] with start/end/step in the same schedule.

Continuous Schedule Window

Continuous windows are explicit:

text
schedule(start = 0h, duration = 24h, mode = continuous, observe_every = 1h)

Continuous schedules use start + (end | duration). They do not use step or at=[...].

Parameterized continuous windows are resolved at plan time:

text
protocol Perfuse(window = 24h) {
    repeat perf in schedule(start = 0h, duration = window, mode = continuous) {
        ...
    }
}

Conditionals

text
if condition {
    target << [source:5uL];
} else {
    target << [buffer:5uL];
}

The condition must be decidable by the compiler/runtime path that owns the values involved.

break and continue

continue; skips the remaining statements in the current loop iteration.

text
repeat 10 {
    if skip_condition {
        continue;
    }
    target << [source:1uL];
}

break; exits the nearest enclosing repeat.

text
repeat 10 {
    if stop_condition {
        break;
    }
    target << [source:1uL];
}

break and continue are only valid inside repeat blocks.

Released under the Apache-2.0 license.