Hacker News new | ask | show | jobs
by tomp 1393 days ago
No, it’s actually because , (comma) denotes a tuple.

    [1, 2; 3, 4]
is a list of tuples, of type (int * int) list, equivalent to

    [(1, 2); (3, 4)]
3 comments

I never understood the motivation for allowing tuples without surrounding parens. There are a few very simple functions that look cuter this way, but it constantly trips me up in more complex situations.
No parentheses can be nice for cleaner pattern matching, e.g. something like this:

  match a, b with
  | 1, 2 -> x
  | _ -> y
This phenomenon is actually another example of the phenomenon he mentions. In strict precedence parsing, operators are assigned meaning rather than productions of a grammar (which would could those operators in distinct contexts), so once you've decided a comma indicates a tuple, it's easier to just allow this syntax.
The "comma makes a tuple" behavior is a big gotcha I've experienced in Python. I wish that behavior didn't exist
Which version of that are you talking about in Python? The biggest related gotcha I've seen in Python is when you have a trailing comma `x = 1,` and accidentally create a tuple.
Yea that’s the most common gotcha