V: multi-dimensional array support

Created on 2 Oct 2019  路  8Comments  路  Source: vlang/v

Multi-dimensional array comes in handy in a lot of situation, it should be implemented as soon as possible.

Feature Request

Most helpful comment

oh, please, please.
this is needed more then most other addon stuff.

All 8 comments

oh, please, please.
this is needed more then most other addon stuff.

works for me:

fn main() {
        a := [1,2,3]
        b := [[1,2,3], [4,5,6]]
        println(b[1][0])
}

@medvednikov not the unlucky me:

fn main() {

    a := [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
    b := [[1, 2], [3, 4]]

    println(a[0][0][0]) // not working
    println(b[1][0]) //=> 3
}
main.v:7:22: expected `)` but got `[`
    6|     println(b[0][0])
    7|     println(a[0][0][0])
                            ^
    8| }

Thanks @87Idiot, only 2d arrays seem to work.

Will fix today.

@medvednikov It's still not working?

I would be nice if this case could be handled as well:

mut multi := [][]string

This happens often when I want to generate an array of arrays in i.e. a for loop.

I see in game_of_live example of matrix usage, and set value works new_field[i] [j] =. But if i use matrix in struct it not works.

struct Matrix {
mut:
  data [] []f64
}

m.data[x] [y] = v
a.v:14:17: unexpected token: `=`

   14|   m.data[x] [y] = v

                       ^

Fixed

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cjmxp picture cjmxp  路  3Comments

ArcDrake picture ArcDrake  路  3Comments

jtkirkpatrick picture jtkirkpatrick  路  3Comments

oleg-kachan picture oleg-kachan  路  3Comments

markgraydev picture markgraydev  路  3Comments