raz / conform / run / Strings.raz

39 lines · 962 B · raw · history · last change 264716cb

1module Strings;
2import Out;
3
4const greeting = "hello";
5
6var buf: [8]U8;
7
8proc count(xs: []const I64): I64;
9var i: INT; s: I64;
10begin
11 s := 0;
12 for i := 0 to LEN(xs) - 1 do s := s + xs[i]; end;
13 return s;
14end;
15
16proc main*;
17var a: []const U8; b: [5]U8; c: [3]I64; d: [][]const U8;
18begin
19 a := "hello";
20 if a = greeting then Out.str("eq "); end;
21 if a # "help" then Out.str("ne "); end;
22 if "abc" = "abc" then Out.str("lit "); end;
23 b := "hello";
24 if b = a then Out.str("arr "); end;
25 buf := "hi";
26 if buf[0..2] = "hi" then Out.str("buf "); end;
27 Out.int(I64(buf[5])); Out.str(" ");
28 Out.int(LEN(greeting)); Out.str(" ");
29 Out.int(LEN(a[1..3])); Out.ln;
30 c := [1, 2, 3];
31 Out.int(count(c)); Out.str(" ");
32 Out.int(count([10, 20, 30, 40])); Out.str(" ");
33 Out.int(count([])); Out.ln;
34 d := ["one", "two", "three"];
35 Out.str(d[2]); Out.str(d[0]); Out.ln;
36 Out.str("é\u{263A}\x41\n");
37end;
38
39end Strings.