Replies: 7 comments
-
I like this idea! @spytheman and @medvednikov what do you think about it? |
Beta Was this translation helpful? Give feedback.
-
I can see it's useful in multiple use cases, however, In your case, the actual case is safe since you forced casting index into We could do some enhancement if providing |
Beta Was this translation helpful? Give feedback.
-
The problem comes if you declare the array len to be larger than the array type supports arr := []u8{len: 10000, init: it} Should V silently "wrap" the values back to 0 after it hits 255? Would you want this in all possible cases? It is more explicit (and therefore safer) if you specify the type yourself. The safer version of my example would be arr := []u8{len: 10000, init: u8(it % 256)} |
Beta Was this translation helpful? Give feedback.
-
By the way, I think |
Beta Was this translation helpful? Give feedback.
-
I understand, that
From my perspective is much more intuitive that in case the array index reaches the underlying type maximum value the remaining slots to be filled out with the array type |
Beta Was this translation helpful? Give feedback.
-
@esimov in general, I agree with you, and think it's a good idea. |
Beta Was this translation helpful? Give feedback.
-
By the way, thanks to @ChAoSUnItY, |
Beta Was this translation helpful? Give feedback.
-
Describe the feature
Recently I was trying out the V language and I liked in how many ways you can initialize an array, but one aspect I consider a bit annoying, is that in case you want to populate an array on initialization using the
it
variable you have to explicitly define its type. Wouldn't be possible to infer its type directly without using type assertion?For example if I'm trying to initialize an
u8
array the compiler expect the type of theit
variable to beu8
, so I need to type cast tou8
. It would be much nicer the compiler being able to detect theit
variable underlying type without having to explicitly define its concrete type.Here if I'm not specifying the
it
type the compiler will throw the following error:Use Case
I would propose instead of this:
Actual:
the compiler being able to infer the
it
variable type based of the array's underlying type.Desired:
Version used
V 0.3.3
Environment details (OS name and version, etc.)
Beta Was this translation helpful? Give feedback.
All reactions