Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any difference between `*x` and `x*`?

Tags:

rascal

I found in some demo code, both *x and x* are used. Sometimes, the star is also used on types, like *int xs. In the help, only the pattern Var* is documented. Is there any difference between putting the star before or after a pattern variable?

like image 930
day Avatar asked Feb 03 '26 06:02

day


1 Answers

Good question. The answer is both yes and no:

  • Yes: The post-fix * is deprecated, since it triggers syntactical ambiguity with post-fix transitive closure in some weird contexts on the expression side of things. This does not happen in patterns, but for consistency we want to have the prefix * mean "splat" in patterns and "splice" in expressions, as dual operators, and remove the post-fix * to avoid confusion.
  • No: when applied to a variable in a pattern they will have the same semantics.

So, please use the prefix + and prefix * when possible to avoid upgrade pain in the future when we remove postfix * and + from the language.

like image 150
Jurgen Vinju Avatar answered Feb 04 '26 18:02

Jurgen Vinju



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!