How to add a Feature in Julia Lang

I would like to use Sets like this:

julia> Set(1,2,3)
Set{Int64} with 3 elements:
  2
  3
  1

I want to add one overload.

julia> Set(args::T...) where T = Set(args)
Set
julia> Set(args::Any...) = Set(args)
 Set

How would I propose that (on Github)?

This is actually how sets used to work, if I remember right. The problem — and the reason why it was deprecated — is that it introduces a confusion between what Set(1:2) means: is it what it’d mean if it were a part of Set(1:2, 3:4)? Is it the set with a single 1:2 element or is it the Set with a 1 and a 2?

9 Likes

First search the github issue tracker Issues · JuliaLang/julia · GitHub for related issue or discussions about something related to your proposal. This is vital so that you don’t waste your time, or the time of the julia devs. I’ve been guilty a few times now of proposing something only to find out that there was already several old discussions that I missed previously.

The second step is to open an issue to propose and discuss your change (this is not strictly necessary, but is often a good idea so you don’t waste effort making something that is unacceptable) Sign in to GitHub · GitHub

Once the idea has been discussed, you then fork the julia repo on github

See the fork button on the top right? Click that. Next, you make the changes you want to propose in your forked copy of the julia repo, and then you will see a bar in your copy

that says ‘pull request’. Click that, and it will allow you to open what’s called a pull request to the julia repo and then people can discuss your specific implementation of the proposed idea.

Finally, it’s important to be humble and understanding when people criticize your proposal. I like to think I’m pretty good at receiving criticism, but sometimes, when I work on something that I think is cool or clever, it’s really hard to hear someone you respect say that it is a bad idea or that they disagree with it. It’s important to remember that Julia is a language used by many different people and they all have deep stakes in it, so proposals must go through rigorous discussion before they’re accepted. The people reviewing these proposals are often very knowledgeable, and see many proposals every day. We all have to do our best to not take it personally when our ideas don’t work out.

10 Likes

In other words, it’s really valuable to do a bit of searching to see if it’s been proposed before and if there have been any prior discussions or decisions before investing to much energy into the idea. :slight_smile:

4 Likes

You might want to check out @kslimes’s awesome tutorial on how to start contributing to Julia: Making a first Julia pull request | Katharine Hyatt

4 Likes

Ahh, didn’t think of that. That’s actually a good point

2 Likes

Here you go:

https://github.com/JuliaLang/julia/pull/22477

4 Likes

One thing you can do is define your own factory function, e.g.

julia> set(args...) = Set(args)
set (generic function with 1 method)

julia> set(1,2,3)
Set{Int64} with 3 elements:
  2
  3
  1

This way, the Set constructor is unchanged and there’s no ambiguity with it, but you can also have the constructor you want. This is a rather common pattern that ends up being needed. For instance Tuple versus tuple:

julia> Tuple(1,2,3)
ERROR: MethodError: no method matching Tuple(::Int64, ::Int64, ::Int64)
Closest candidates are:
  Tuple(::Any) where T<:Tuple at tuple.jl:230
Stacktrace:
 [1] top-level scope at REPL[6]:1

julia> tuple(1,2,3)
(1, 2, 3)

and

julia> Tuple((1,2,3))
(1, 2, 3)

julia> tuple((1,2,3))
((1, 2, 3),)
6 Likes