Hi everyone, my first post in this forum!
I'm just starting with Nim and wonder what is the most idiomatic way to initialize a uint array? I'd like to mix characters and ints if possible and let the compiler do appropriate casting for me. The following lines does not compile though:
var test : array[3,uint] = ['B', 12,32]
So far I need to cast individual (char elements elements myself which I admit is not very clean.
var test : array[3,uint] = cast[array[3,uint]]([cast[uint]('B'), 12,32])
Cheers, kuba
var test: array[3, uint] = [uint 'B', 12, 32]
var test2 = ['B'.uint, 12, 32]
var test3 = [uint 'B', 12, 32, uint 'c'] # if there are any more characters, you have to convert them explicitly
var test4 = [200u, 300, 400] # a u or 'u suffix works for number literals
Type casts should be your last resort. In this case a simple type conversion with uint() works.