Ok this is embarrassing but what's Nim's equivalent of printf? In particular
stringifying a bunch of bytes as a hex string? I see a format proc in strutils
but it seems to only accept string varargs. I was trying to put together a
crude guid generation function I have in Golang (see below) but I'm stumped.
func guid() string{
f, _ := os.Open("/dev/urandom", os.O_RDONLY, 0)
b := make([]byte, 16)
f.Read(b)
f.Close()
uuid := fmt.Sprintf("%x-%x-%x-%x-%x", b[0:4], b[4:6], b[6:8], b[8:10],
b[10:])
return uuid
}
proc guid():string=
let f = open("/dev/urandom")
var b:array[16, byte]
discard readBytes(f, b, 0, 16)
close(f)
format("%x-%x-%x-%x-%x", b[0..4], b[4..6], b[6..8], b[8..10], b[10..15])
I understand I can use printf directly from C but don't know what function
signature to use!
Thanks for any help!