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?

2018-02-13 15:36:24
Does it work as expected if you only provide the type annotation on the first element? 2018-02-13 15:53:32
yes! that is it, thanks! 2018-02-13 15:58:04
i'd really like to be able to define arrays like this:
let myArray: array[auto, float32] = [1, 2, 3, 4]
2018-02-13 20:03:23

@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]

2018-02-13 23:15:08

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]

2018-02-14 08:47:15
I forgot about mapLiterals, but your snippet is perfect Jehan. 2018-02-14 10:11:40