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

Better suggestion for replacement of [a] #11369

Merged
merged 1 commit into from
May 28, 2015

Conversation

tomasaschan
Copy link
Member

On Julia master:

julia> [1:5]
WARNING: [a] concatenation is deprecated; use [a;] instead
...

With this PR:

julia> [1:5]
WARNING: [a] concatenation is deprecated; use collect(a) instead
...

Ever since this was introduced, I've been silently annoyed by the suggestion to use [a;] - the syntax feels like a hack, and for users that aren't familiar with Julia already, it's far from obvious why there's a semi-colon there, and what the difference between [a] and [a;] is. However, I stayed silent, since I didn't have a better suggestion.

Now I do :)

I suggest we use collect(a) instead, for the following reasons:

  • it's obvious what it does, much more so than [a;]
  • it generalizes nicely when you want a different eltype, e.g. collect(Float64, 1:5)
  • from what I understand of the discussion in WIP: Make [a, b] non-concatenating #8599 most of the opinions raised favored collect(a) over [a:] - not sure why it didn't happen. The only argument against collect was that it's slower (for UnitRanges, specifically), but Jeff quickly retorted that with "No problem, I will make collect faster."
  • it just feels more Julian to me :)

I do realize that it doesn't generalize as nicely to higher dimensions, but since part of my problem with using ; in the 1D case is that it feels like something that belongs with multidimensional arrays, I don't really see that as an argument against this change.

@toivoh
Copy link
Contributor

toivoh commented May 20, 2015 via email

1 similar comment
@kmsquire
Copy link
Member

👍

@tomasaschan
Copy link
Member Author

In the long run, perhaps [a;] should also be deprecated to try to eradicate it from code bases out there, but I'm not sure it's so nice to be recommended an alternative syntax one day, just to have it deprecated the next... :P

@Jutho
Copy link
Contributor

Jutho commented May 20, 2015

+1

@nolta
Copy link
Member

nolta commented May 20, 2015

Doesn't this print [collect(a)]?

@tomasaschan
Copy link
Member Author

@nolta; good point, I'll fix that ASAP. Filed this from an edit on github mostly because I thought it was ridiculous too open an issue for such a small a change without making it a PR 😏

Still, it seems there is support for favoring collect(a) over [a;].

@ScottPJones
Copy link
Contributor

👍

1 similar comment
@prcastro
Copy link
Contributor

👍

jakebolewski added a commit that referenced this pull request May 28, 2015
Better suggestion for replacement of [a]
@jakebolewski jakebolewski merged commit 572a892 into JuliaLang:master May 28, 2015
@garrison
Copy link
Member

Was @nolta's point ever resolved?

@jakebolewski
Copy link
Member

My bad, should be fixed.

@garrison
Copy link
Member

thanks!

@tomasaschan
Copy link
Member Author

@garrison, @jakebolewski No, I never got to fixing that. Was it fixed somewhere else, or should I submit a new patch to fix it?

@tkelman
Copy link
Contributor

tkelman commented May 29, 2015

ec37d6d

@tomasaschan
Copy link
Member Author

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants