Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fully document array-like literal initializers #7292

Closed
pao opened this issue Jun 17, 2014 · 5 comments
Closed

Fully document array-like literal initializers #7292

pao opened this issue Jun 17, 2014 · 5 comments
Labels
docs This change adds or pertains to documentation

Comments

@pao
Copy link
Member

pao commented Jun 17, 2014

The documentation on the Punctuation page isn't really useful if you're trying to specify a particular array structure, unless you already know MATLAB (and even then there are important differences). The literal syntaxes using [], {}, and (,) should be separated out into their own thing. Not sure what part of the manual is best. Examples should be included as well.

@kmsquire
Copy link
Member

I cringe when I see the documentation for the special concatenation syntax (which was already there). I understand its usefulness in linear algebra... and I've been trying to justify it (unsuccessfully) to a new Julia user who wasn't doing linear algebra and couldn't figure out why he couldn't create hierarchical array structures (ala JSON).

@StefanKarpinski
Copy link
Member

I agree it's a bad situation for general programming. I'm in favor of using |A B| for concatenation – curlies just aren't associated with block matrix syntax. They could get used for dicts and set literals(!).

@JeffBezanson
Copy link
Member

I really regret imitating that other language's block matrix syntax.

The primary syntax should be for constructing arrays from elements, and supporting full N-d so that all arrays have a standard notation.

There might be some way to combine dict and set literals (e.g. write a dict as a set of tuples?), but I suspect we'll just have to forgo set literals.

We might be able to keep using spaces and semicolons to concatenate ([a b], [a; b], [a;]). You'd have to write [1:n;] to expand a range but we'd just have to live with that.

Another option is to leave [ ] alone, and reclaim { } for the new non-concatenating N-d array syntax.

@johnmyleswhite
Copy link
Member

This is a slightly ridiculous proposal, but what about repetition of commas to indicate dimension?

  • {1, 2, 3} is Array(Int, 3).
  • {1,, 2,, 3} is Array(Int, 1, 3)
  • {1,,, 2,,, 3} is Array(Int, 1, 1, 3)
  • ...
  • {1, 2,, 3, 4} is Array(Int, 2, 2) and equal to our current [1 3; 2 4].

@pao
Copy link
Member Author

pao commented Jun 18, 2014

Nice thought, but it breaks down when you use this for 2D (which we do). With that proposal and multiline, you end up with:

> { 1, 2 ,,
    3, 4}

2x2 Array{Int64, 2}:
 1  3
 2  4

You have to mentally transpose the layout. I like that it can extend to higher dimensions though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation
Projects
None yet
Development

No branches or pull requests

5 participants