| 1 | module Strings; |
| 2 | import Out; |
| 3 | |
| 4 | const greeting = "hello"; |
| 5 | |
| 6 | var buf: [8]U8; |
| 7 | |
| 8 | proc count(xs: []const I64): I64; |
| 9 | var i: INT; s: I64; |
| 10 | begin |
| 11 | s := 0; |
| 12 | for i := 0 to LEN(xs) - 1 do s := s + xs[i]; end; |
| 13 | return s; |
| 14 | end; |
| 15 | |
| 16 | proc main*; |
| 17 | var a: []const U8; b: [5]U8; c: [3]I64; d: [][]const U8; |
| 18 | begin |
| 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"); |
| 37 | end; |
| 38 | |
| 39 | end Strings. |