raz / conform / run / FirstUse.raz

34 lines · 1001 B · raw · history · last change 264716cb

1module FirstUse;
2import Out, Str, Table := Table([]const U8, Colour, Str.hash, Str.eq),
3 Ints := Pile(I64), More := Pile(I64), Never := Loud(I64), Ones := Loud(U8);
4import SYSTEM;
5
6type Colour = (red, green, blue);
7
8var names: Table.Table; (* Table is made here, after Colour *)
9
10proc show(k: []const U8);
11var c: Colour; found: BOOL;
12begin
13 c, found := Table.get(SYSTEM.ADR(names), k);
14 Out.str(k);
15 if not found then Out.str(" -"); elsif c = red then Out.str(" red"); else Out.str(" not red"); end;
16 Out.ln;
17end;
18
19(* Ones is first used in a procedure, and made before its code *)
20proc main*;
21var a: Ints.Pile; b: More.Pile;
22begin
23 a := b; (* two imports, one instance *)
24 if a.len = 0 then Out.str("an empty list\n"); end;
25 Out.str("in main, Ones has size "); Out.int(Ones.size); Out.ln;
26 show("sky");
27 show("rose");
28 show("grass");
29end;
30
31begin
32 _ := Table.put(SYSTEM.ADR(names), "rose", red);
33 _ := Table.put(SYSTEM.ADR(names), "sky", blue);
34end FirstUse.