A numeric limit can gate how much input a program accepts before it stops accumulating work.

Program

Play the program to choose a limit and watch the accepted count change.

limit
limit_gate_config.rs
Replay: real traced execution (multi-file project)
fn main() {
    let limit = 2;
    let mut accepted = 0;
    for value in [3, 8, 13] {
        if value <= limit * 5 {
            accepted += 1;
        }
    }
    println!("limit={limit} accepted={accepted}");
}
fn main() {
    let limit = 1;
    let mut accepted = 0;
    for value in [3, 8, 13] {
        if value <= limit * 5 {
            accepted += 1;
        }
    }
    println!("limit={limit} accepted={accepted}");
}
fn main() {
    let limit = 3;
    let mut accepted = 0;
    for value in [3, 8, 13] {
        if value <= limit * 5 {
            accepted += 1;
        }
    }
    println!("limit={limit} accepted={accepted}");
}
  1. limit ← 2, accepted ← 0

    1fn main() {2    let limi→ 2t = 2; //@limit=2, 1, 33    let mut accepte→ 0d = 0;4    for value in [3, 8, 13] {
  2. for value in [3, 8, 13]

    pass 1 of 3
    3let mut accepted = 0;4for valu3e in [3, 8, 13] {5    if value <= limit * 5 {
    All 3 passes — pass 1 is the card above
    passvaluelimitaccepted
    1320 1
    2821 2
    313
  3. accepted ← 1

    pass 1 of 2
    4for value in [3, 8, 13] {5    if valu3e <= limi2t * 5 {6        accepte→ 1d += 1;7    }
  4. accepted ← 2

    pass 2 of 2
    4for value in [3, 8, 13] {5    if valu8e <= limi2t * 5 {6        accepte→ 2d += 1;7    }
  5. println!("limit={limit} accepted={accepted}");

    8    }9    println!("limit={limit} accepted={accepted}");10}
    outputlimit=2 accepted=2
  1. limit ← 1, accepted ← 0

    1fn main() {2    let limi→ 1t = 1;3    let mut accepte→ 0d = 0;4    for value in [3, 8, 13] {
  2. for value in [3, 8, 13]

    pass 1 of 3
    3let mut accepted = 0;4for valu3e in [3, 8, 13] {5    if value <= limit * 5 {
    All 3 passes — pass 1 is the card above
    passvaluelimitaccepted
    1310 1
    28
    313
  3. accepted ← 1

    4for value in [3, 8, 13] {5    if valu3e <= limi1t * 5 {6        accepte→ 1d += 1;7    }
  4. println!("limit={limit} accepted={accepted}");

    8    }9    println!("limit={limit} accepted={accepted}");10}
    outputlimit=1 accepted=1
  1. limit ← 3, accepted ← 0

    1fn main() {2    let limi→ 3t = 3;3    let mut accepte→ 0d = 0;4    for value in [3, 8, 13] {
  2. for value in [3, 8, 13]

    pass 1 of 3
    3let mut accepted = 0;4for valu3e in [3, 8, 13] {5    if value <= limit * 5 {
    All 3 passes — pass 1 is the card above
    passvalue
    13
    28
    313
  3. accepted ← 1

    pass 1 of 3
    4for value in [3, 8, 13] {5    if valu3e <= limi3t * 5 {6        accepte→ 1d += 1;7    }
    All 3 passes — pass 1 is the card above
    passvalueaccepted
    130 1
    281 2
    3132 3
  4. println!("limit={limit} accepted={accepted}");

    8    }9    println!("limit={limit} accepted={accepted}");10}
    outputlimit=3 accepted=3

Follow the Gate

  1. limit starts at 2.
  2. The gate is value <= limit * 5, so the cutoff is 10.
  3. accepted starts at 0.
  4. Values 3 and 8 pass the gate, so accepted becomes 2.
  5. Value 13 is above 10, so the program prints limit=2 accepted=2. | limit | cutoff limit * 5 | accepted values | output | | ---: | ---: | --- | --- | | 1 | 5 | 3 | limit=1 accepted=1 | | 2 | 10 | 3, 8 | limit=2 accepted=2 | | 3 | 15 | 3, 8, 13 | limit=3 accepted=3 |
limit `limit` is runtime configuration that changes the acceptance threshold.
gate The `if` condition accepts only values below the configured threshold.
accumulator `accepted` records how much input passed the gate.

Exercise: limit_gate_config.rs

Reproduce limit=2 accepted=2, then use limit 1 and 3 to predict limit=1 accepted=1 and limit=3 accepted=3.