raz / conform / run / ArrayConst.raz

53 lines · 1.5 KiB · raw · history · last change 264716cb

1module ArrayConst;
2import Out;
3
4type Color = (red, green, blue);
5
6const
7 Primes*: [5]I64 = [2, 3, 5, 7, 11];
8 Small: [4]U8 = [1, 2, 0FFH, 'A'];
9 Halves: [3]F64 = [0.5, 1.5, -2.5];
10 Narrow: [2]F32 = [0.25, 3.0];
11 Flags: [3]BOOL = [true, false, true];
12 Colors: [2]Color = [blue, red];
13 Mixes: [2]set of Color = [{red, blue}, {}];
14 Neg: [3]I16 = [-1, -32768, 32767];
15
16proc sum(a: []const I64): I64;
17var s: I64; i: INT;
18begin
19 for i := 0 to LEN(a) - 1 do s := s + a[i]; end;
20 return s;
21end;
22
23proc first(a: [5]I64): I64;
24begin
25 return a[0];
26end;
27
28proc main*;
29const Local: [2]I32 = [40, 2];
30var a: [5]I64; i: INT;
31begin
32 for i := 0 to LEN(Primes) - 1 do Out.int(Primes[i]); Out.str(" "); end;
33 Out.ln;
34 Out.int(sum(Primes)); Out.str(" ");
35 Out.int(sum(Primes[1..3])); Out.str(" ");
36 Out.int(first(Primes)); Out.ln;
37 a := Primes;
38 a[0] := 1;
39 if a # Primes then Out.str("differ "); end;
40 a[0] := 2;
41 if a = Primes then Out.str("same"); end;
42 Out.ln;
43 for i := 0 to 3 do Out.int(I64(Small[i])); Out.str(" "); end;
44 Out.ln;
45 if (Halves[0] = 0.5) and (Halves[2] = -2.5) and (Narrow[1] = 3.0) then Out.str("reals "); end;
46 if Flags[0] and not Flags[1] then Out.str("bools "); end;
47 if (Colors[0] = blue) and not (green in Mixes[0]) and (blue in Mixes[0]) then Out.str("enums"); end;
48 Out.ln;
49 Out.int(I64(Neg[0])); Out.str(" "); Out.int(I64(Neg[1])); Out.str(" "); Out.int(I64(Neg[2])); Out.ln;
50 Out.int(I64(Local[0] + Local[1])); Out.str(" "); Out.int(LEN(Local)); Out.ln;
51end;
52
53end ArrayConst.