grain icon indicating copy to clipboard operation
grain copied to clipboard

Shorthand syntax for supplying a parameter

Open alex-snezhko opened this issue 1 year ago • 1 comments

It would be nice to have a punning syntax for passing a binding as a labeled argument with the same name

Possible syntaxes:

let add = (num1, num2) => num1 + num2

let num2 = 2
add(1, ~num2)
add(1, num2=)
add(1, num2=~) // (or some other special character)

alex-snezhko avatar Aug 18 '24 02:08 alex-snezhko

I feel like the syntax examples here all have problems:

  • ~ seems a little random as we don't have precedent in grain.
  • num2= seems like it could cause confusion it's very easy to miss the comma in num2=,3

There have been quite a few times already though where I wanted this, my thoughts are a slightly better syntax would be postfix = like =num2, then it's 3,=num2 or num3,=num2 where the comma seems harder to miss, though I am still not a major fan.

If our goal is just to reduce the amount of typing programmers have todo with the alias however leaning on lsp autocorrect seems like a slightly better way of doing this.

spotandjake avatar Apr 23 '25 22:04 spotandjake