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

push! on Dicts #9295

Closed
Keno opened this issue Dec 10, 2014 · 5 comments
Closed

push! on Dicts #9295

Keno opened this issue Dec 10, 2014 · 5 comments
Assignees
Milestone

Comments

@Keno
Copy link
Member

Keno commented Dec 10, 2014

Now that we have the nice syntax for pairs, I think it would be convenient for

a = Dict()
push!(a,1=>2)

to work. At the moment we have to use

push!(a,1,2)

which probably should be reflected in the docs for push!, which are right now:

  push!(collection, items...) → collection

  Insert items at the end of collection.

  push!([1,2,3], 4) == [1,2,3,4]
@ivarne
Copy link
Sponsor Member

ivarne commented Dec 10, 2014

+1
If push!(a,1,2) is a varargs function to push arbitrary number of items to the collection, the current definition for Associative is inconsistent. We should either remove the varargs fallback, or require push!(a,(1,2)), push!(a, [1,2]) or push!(a, 1=>2).

@johnmyleswhite
Copy link
Member

+1

@JeffBezanson
Copy link
Sponsor Member

Let's definitely deprecate push!(t::Associative, key, v), use push!(dict, 1=>2) instead, and continue to allow pushing several items using varargs.

@ivarne ivarne added this to the 0.4 milestone Dec 10, 2014
ivarne added a commit that referenced this issue Dec 11, 2014
Deprecate `push!(a, k, v)` in favor of `push!(a, k=>v)` because the old
signature was inconsistent with the varargs version of `push!` to add
multiple elements to a collection.

TODO: Add tests
@ivarne
Copy link
Sponsor Member

ivarne commented Dec 11, 2014

I made a half attempt at fixing this, and I'm somewhat disappointed that it didn't break any tests. I don't have time for more today, but anyone is welcome to git checkout in/issue-9295 and add proper testing of the new push! method, if they can beat me to it.

@ivarne ivarne self-assigned this Dec 11, 2014
bicycle1885 added a commit to bicycle1885/julia that referenced this issue Jan 24, 2015
@bicycle1885
Copy link
Member

@ivarne
I cherry-picked your half fix and added varargs support and some tests.
But it breaks very rare (I hope) backward compatibility: push!ing a pair of Pair key and Pair value.

One workaround would be using explicit type parameters:

push!{K,V}(::Associative{K,V}, ::Pair{K,V}, ::Pair{K,V})

but this will change the semantic of push!.

@ivarne ivarne closed this as completed in e725653 Jan 24, 2015
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

No branches or pull requests

6 participants