I have a vague memory of someone tweeting me a way to avoid having to put a type annotation on every field in an array like so:
var gradZ = [ 0'f32, 0'f32, 0'f32, 0'f32, 1'f32, 1'f32,-1'f32,-1'f32, 1'f32, 1'f32,-1'f32,-1'f32]
But I can't remember, is there a way?
let myArray: array[auto, float32] = [1, 2, 3, 4]
@Arrrrrrrrr : if you are on devel, you can use mapLiterals from sequtils
import sequtils let x = mapLiterals([0.1, 1.2, 2.3, 3.4], int) doAssert x is array[4, int]
I generally use the fact that you can omit the parentheses (or dot) for conversions of literals, leading to a pretty natural looking notation:
let a = [float 1, 2, 3, 4] let b = [int8 1, 2, 3, 4]