← demo0x4535a2…ec75Succeededblock 90
No position yet0 / 124
FetchingOpeningPositioning
noir
Narrow session: Code, Call Trace and Values only, read-only. The event log and stepping need a wider viewport.
Code
1 threshold = "300"
2 orders = "4"
1 // TOUR: program output and the event log
2 //
3 // The subject is the event log — the stream of things the execution SAID, as
4 // distinct from the values it held. In this language that stream is `print`,
5 // `println` and format strings, and it is the only pane whose content a
6 // program author writes directly.
7 //
8 // The entries are deliberately varied: bare text, a single interpolated value,
9 // several values in one line, output from inside a loop, and output from a
10 // nested frame — so the log is a sequence a reader can follow rather than the
11 // same sentence repeated.
12
13 struct Order {
14 id: u32,
15 qty: u32,
16 unit_price: u32,
17 }
18
19 unconstrained fn line_total(o: Order) -> u32 {
20 let total = o.qty * o.unit_price;
21 // A format string interpolates BINDINGS, not expressions — `{o.qty}` is a
22 // compile error in this language, so the fields are bound first. The
23 // locals that exist only to be printed are worth seeing: they are what
24 // the event log's text is built from.
25 let id = o.id;
26 let qty = o.qty;
27 let price = o.unit_price;
28 // Output from a nested frame: this entry is written while the call trace
29 // is one frame deeper than the entries around it.
30 println(f" line {id}: {qty} x {price} = {total}");
31 total
32 }
33
34 unconstrained fn apply_discount(total: u32, threshold: u32) -> u32 {
35 if total >= threshold {
36 let discounted = total - (total / 10);
37 println(f" discount applied at threshold {threshold}: {total} -> {discounted}");
38 discounted
39 } else {
40 println(f" no discount: {total} is below {threshold}");
41 total
42 }
43 }
44
45 unconstrained fn main(threshold: u32, orders: pub u32) -> pub u32 {
46 // A bare string with no interpolation at all.
47 println("=== invoice ===");
48
49 let mut running: u32 = 0;
50
51 // Output from inside a loop: one entry per iteration, each carrying the
52 // iteration's own values, so the log and the loop rail line up rung for
53 // rung.
54 for i in 0..orders {
55 let line_no = i + 1;
56 let o = Order { id: line_no, qty: i + 2, unit_price: 10 + i };
57 let t = line_total(o);
58 running = running + t;
59 println(f" running total after line {line_no}: {running}");
60 }
61
62 // `print` without a newline, then `println` completing the same line —
63 // two events that a reader sees as one sentence.
64 print("subtotal: ");
65 println(running);
66
67 let final_total = apply_discount(running, threshold);
68
69 // Several values interpolated into one entry.
70 println(f"orders={orders} threshold={threshold} subtotal={running} total={final_total}");
71 println("=== end ===");
72
73 final_total
74 }
1 [package]
2 name = "tour_events"
3 type = "bin"
4 authors = ["BlockTracer capability tour"]
5
6 [dependencies]
Event Log

The recorded event stream is in the published recording. Reading it needs the replay engine, which this page has not started.

Call Trace

The call structure is in the published recording. Reading it needs the replay engine, which this page has not started.

Values

The recorded values are in the published recording. Reading them needs the replay engine, which this page has not started.