umka-lang icon indicating copy to clipboard operation
umka-lang copied to clipboard

Name placeholder (like `_` in Go)

Open vtereshkov opened this issue 4 years ago • 1 comments

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

vtereshkov avatar May 02 '21 22:05 vtereshkov

@marekmaskarinec It would not be easy, but I'll consider implementing it.

vtereshkov avatar May 02 '21 22:05 vtereshkov

If this is limited to declarations, as it usually is then I think I know what to do.

ske2004 avatar Feb 18 '24 15:02 ske2004

@skejeton Not only declarations. Also assignments, the for...in loop, etc., etc.

Before we start, we need to answer several questions. For example,

  1. Do we really need it after #329 is done? @marekmaskarinec ?
  2. 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.
  3. 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?
  4. 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.

vtereshkov avatar Feb 18 '24 16:02 vtereshkov

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)
                }
        }
}

marekmaskarinec avatar Feb 18 '24 19:02 marekmaskarinec