Name placeholder (like `_` in Go)
Would it be possible to add something like _? It can be very useful.
Originally posted by @marekmaskarinec in https://github.com/vtereshkov/umka-lang/issues/70#issuecomment-830662784
@marekmaskarinec It would not be easy, but I'll consider implementing it.
If this is limited to declarations, as it usually is then I think I know what to do.
@skejeton Not only declarations. Also assignments, the for...in loop, etc., etc.
Before we start, we need to answer several questions. For example,
- Do we really need it after #329 is done? @marekmaskarinec ?
- The Go spec has 34 mentions of "blank", i. e., the
_. All of them (except those related to generics) may or may not be applicable to Umka. - How should it be implemented internally? As an identifier or as a new token kind? If the former, what type should it have? And in how many places should it be treated specially?
- How to properly skip the right-hand side expressions in
a, _, _, b, _, c, d = e, f, g, h, i, j, k? They can have different sizes. And none of them should remain on the stack as garbage.
I don't think this issue is worth implementing, since we now have #329. It may be useful in for loops, but it's actually not required thanks to variable shadowing. This works just fine:
fn main() {
a := []int{ 1, 2, 3 }
for _,i in a {
for _,j in a {
printf("%d * %d = %d\n", i, j, i * j)
}
}
}