echo in #odinlang

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.

About mcturra2000

Computer programmer living in Scotland.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s