grain
grain copied to clipboard
Shorthand syntax for supplying a parameter
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)
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 innum2=,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.