have been playing with Julia for a few weeks. (I have used MATLAB, but more of a Python background.) I find the following almost impossible to remember when typing arrays manually:
- spaces yield horizontal arrays
- commas yield vertical arrays
- semicolons yield vertical arrays
- semicolons and spaces yield 2x2 arrays
- commas and spaces yield errors
- commas with subarrays yield arrays-of-arrays
- semicolons with subarrays yield flat arrays
It’s hard to remember because I can’t see a philosophy. Commas and semicolons seem to just behave differently in ways that are not predictable (from remembering just 6 out of the above 7 facts, I can never deduce the 7th fact). Maybe semicolons are distinguished from commas by concatenating “more aggressively”, but if this is the only difference, why can’t matrices be declared as
[1 2, 3 4]?
It creates confusion for me later in the documentation, because for later statements (e.g. “An array with a specific element type can be constructed using the syntax
T[A, B, C, ...].”) I am not sure if it is supposed to be general, or refers to a particular property of
;. (Of course, in this case it doesn’t, but as a beginner I have to test each case to check.)
What’s the logic distinguishing
; for array creation?