From c1bd84464c3e338f6fc4df8ac674f706cc10114f Mon Sep 17 00:00:00 2001 From: Toni Date: Wed, 12 Nov 2025 12:04:13 +0100 Subject: [PATCH] new README example --- README.md | 20 +++++++++++++------- src/std.zr | 4 ++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 2790da2..f08d796 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,18 @@ A very cool language ## Syntax ```rust -func fib[n: I64] : I64 - if n <= 1 - return n - return fib(n-2) + fib(n-1) - func main[] : I64 - for i in 0..20 - fib(i) |> str.from_i64() |> io.print() + let answer: I64 = math.abs(math.urandom()) % 100 + + while true + io.print("Guess a number: ") + let guess: I64 = io.read_stdin() |> str.trim() |> str.parse_i64() + + if guess == answer + io.print("You win!") + break + else if guess < answer + io.print("Too low!") + else + io.print("Too high!") ``` \ No newline at end of file diff --git a/src/std.zr b/src/std.zr index f8928ce..d86480c 100644 --- a/src/std.zr +++ b/src/std.zr @@ -183,7 +183,7 @@ func str.hex_encode[s: String] : String str.set(out, j, 0) return out -func str.from_hex_digit[d: U8] : I64 +func str._from_hex_digit[d: U8] : I64 if d >= 'a' & d <= 'f' return d - 'a' + 10 if d >= 'A' & d <= 'F' @@ -197,7 +197,7 @@ func str.hex_decode[s: String] : String let out: String = mem.alloc(s_len/2+1) while i < s_len - str.set(out, j, str.from_hex_digit(str.nth(s, i)) * 16 + str.from_hex_digit(str.nth(s, i+1))) + str.set(out, j, str._from_hex_digit(str.nth(s, i)) * 16 + str._from_hex_digit(str.nth(s, i+1))) i = i + 2 j = j + 1