I heard of Odin recently by way of Zig. I decided to see if I could implement echo in Odin. Here’s my code:
package main
import "core:io"
import "core:os"
import "core:fmt"
getchar :: proc() -> (u8, bool) {
buf: [1]u8
n, err := os.read(os.stdin, buf[:])
if(n == 0 || err != os.ERROR_NONE) {
return 0, false
}
return buf[0], true
}
main :: proc() {
fmt.println("What say you?");
for {
c, ok := getchar()
if(!ok) { break }
fmt.printf("%c", c);
}
fmt.println("Bye for now");
}
Who will win, I wonder: Odin or Zig?
Multi-value return statements in Odin look interesting.
I might see if I can implement a toy parser in Odin. What makes it feasible is that Odin supports an “any” type, so hopefully I can get tree-like structures out of it.
It’d be great if Odin had coroutines like Zig can provide with its async functionality. Coroutines are a natural fit for parsers.