V: Can I declare multiple variables at once in V?

Created on 23 Jun 2019  路  7Comments  路  Source: vlang/v

I can declare multiple variables at once in Go.

x, y := "Hello", 10

Now I cannot in V. Will V provide define syntax for multiple variables?

Feature Request

Most helpful comment

Destructuring will be supported.

All 7 comments

I do not think that it is well read. It seems beautiful, but it is hard to read. Better way is write it - line by line.
I mean it's really bad:
a, b, c, d, e, f, g, h, i, j := "Hello", 10, "World", "!", 1, 2, 3, 4, 5, 6

This way is cool. We should not save the lines. Readability code above all:

x := "Hello"
y := 10

I do not think that it is well read.

inputs := os.get_line().split(' ') // '2019 6 20' as a standard input
a := inputs[0].to_i()
b := inputs[1].to_i()
c := inputs[2].to_i()

This way is cool.

a, b, c := os.get_line().split(' ')

or

a, b, c := os.get_line().split(' ').map(int) // future

Is this still a bad idea?

Now it's not bad idea, but if only one inputs you get?

Just idea.

$ a := os.get_line().split(' ') // 'hello' as a standard input
$ println(a)
['hello']
$ a, _ := os.get_line().split(' ') // 'hello' as a standard input
$ println(a)
'hello'



md5-9fe8213920bb9c0d7ed85383d93673a9



$ a := os.get_line().split(' ')[0] // 'hello' as a standard input
$ println(a)
'hello'

What you are talking about is destructuring, not just multiple variable declaration.

Destructuring will be supported.

Update:
Declaring multiple variables at once now works with the new backend.

a, mut b, c := 'v', 'is', 'vood'

Was this page helpful?
0 / 5 - 0 ratings

Related issues

radare picture radare  路  3Comments

lobotony picture lobotony  路  3Comments

cjmxp picture cjmxp  路  3Comments

vtereshkov picture vtereshkov  路  3Comments

XVilka picture XVilka  路  3Comments