# My wishlist for the next version of Julia

**URL:** <https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987>\
**Category:** General Usage\
**Tags:** question, matlab\
**Created:** [October 18, 2021, 4:28pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987 "2021-10-18T16:28:46Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [October 18, 2021, 4:28pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/1 "2021-10-18T16:28:46Z")

</div>

As a Matlab person who recently switched over to Julia, below are some items on my wish list. Many thanks for your consideration!

1. Creating a m x n sized NaN should be as simple as NaN(m, n). Right now, I have to do this:  
`A = fill!(Array{Float64}(undef, m, n), NaN);`

2. If I have two 1-column data with the same size, A and B, I should be able to get an Index by `Ind = A>3 && B<15`. Right now, I would have to use `map` function to broadcast first:

```julia
Ind = map(A, B) do a, b
        a>3 && b<15;
end

```

1. I should be able to initialize an array as `A=[]`, and then append to it as simple as `A = [A; b];` Right now, Julia will complain that I can not append a 0 sized array with a m x n sized array.

2. Automatically handle the conversion between vector and array for Index values, instead of relying on users to decide when to use `A` and when to use `vec(A)`.

3. Function should allow us to define the outcome of the function like: `function [A, B] = f1(x, y, z)`, instead of requiring us to use `return` at the end of the function to return the results.

4. I should be able to use a `sortrows` function, by `B = sortrows(A, Index).` Instead of having to find the Index using `sortperm` first.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [October 18, 2021, 4:41pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/2 "2021-10-18T16:41:13Z")

</div>

> [@leon](#):
>
> Creating a m x n sized NaN should be as simple as NaN(m, n). Right now, I have to do this:  
> `A = fill!(Array{Float64}(undef, m, n), NaN);`

```julia
julia> fill(NaN,(3,4))

3×4 Matrix{Float64}:
 NaN NaN NaN NaN
 NaN NaN NaN NaN
 NaN NaN NaN NaN

```

> [@leon](#):
>
> If I have two 1-column data with the same size, A and B, I should be able to get an Index by `Ind = A>3 && B<15` . Right now, I would have to use `map` function to broadcast first:

You are lucky, that will be possible in V1.7 already:

```julia
julia> A = rand(3,4); B = rand(3,4);

julia> inds = A .> 0.5 .&& B .> 0.5
3×4 BitMatrix:
 0 0 0 0
 0 1 1 0
 0 0 1 1

```

Currently you can already do this:

```julia
julia> A = rand(3,4); B = rand(3,4);

julia> (A .> 0.5) .& (B .> 0.5)
3×4 BitMatrix:
 0 0 0 0
 0 1 1 1
 0 0 1 0

```

(and I don’t see any immediate harm in that, with the parenthesis, maybe someone can correct me)

> [@leon](#):
>
> I should be able to initialize an array as `A=[]` , and then append to it as simple as `A = [A; b];` Right now, Julia will complain that I can not append a 0 sized array with a m x n sized array.

If you are just pushing to `A` for the first time, just do `A = b`.

> [@leon](#):
>
> Automatically handle the conversion between vector and array for Index values, instead of relying on users to decide when to use `A` and when to use `vec(A)` .

The difference between vectors and matrices is a feature, actually, and the old julia and matlab users have discussed many times the advantages of that here.

> [@leon](#):
>
> Function should allow us to define the outcome of the function like: `function [A, B] = f1(x, y, z)` , instead of requiring us to use `return` function at the end of the function to return the results.

that can be done:

```julia
julia> f(x) = 2
f (generic function with 1 method)

julia> f(1)
2

```

(but you need to learn the syntax first).

> [@leon](#):
>
> I should be able to use a `sortrows` function, by `B = sortrows(A, Index).` Instead of having to find the Index using `sortperm` first.

I’m not sure what you want to do here, but isn’t this just this? (edit: or more likely, one of the options here: [Sort matrix based on the elements of a specific column - #5 by nicolas](https://discourse.julialang.org/t/sort-matrix-based-on-the-elements-of-a-specific-column/23475/5) - a function that sorts the matrix as a function of one row may exist, I’m not sure)

```julia
julia> A = rand(3,4);

julia> sort(A, dims=2)
3×4 Matrix{Float64}:
 0.0518517 0.055554 0.248347 0.992392
 0.168324 0.318615 0.857768 0.864286
 0.0809794 0.541194 0.724404 0.911751

```

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [October 18, 2021, 4:47pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/3 "2021-10-18T16:47:39Z")

</div>

> [@lmiq](#):
>
> If you are just pushing to `A` for the first time, just do `A = b` .

You meant `A = copy(b)`, right? Because this is what have more similar semantics with `[A; b]` (when `A` is empty).

---

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [October 18, 2021, 4:50pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/4 "2021-10-18T16:50:22Z")

</div>

Many thanks for sharing these tricks! 👍

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [October 18, 2021, 6:21pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/5 "2021-10-18T18:21:28Z")

</div>

Some additional comments which haven’t been covered already. For what it’s worth I have in the past used Matlab extensively, although I switched away many years ago.

> [@leon](#):
>
> 1. I should be able to initialize an array as `A=[]` , and then append to it as simple as `A = [A; b];` Right now, Julia will complain that I can not append a 0 sized array with a m x n sized array.

You can concatenate an empty matrix if the other dimensions match, e.g. `[zeros(0, 5); zeros(4, 5)]`. But when it comes to the general pattern of repeatedly concatenating to a matrix, that is a pattern which is frequently used in Matlab in lack of better options. Chances are that you will find functions like `push!`, `append!`, and `reduce` to provide satisfactory alternatives.

> [@leon](#):
>
> 1. Function should allow us to define the outcome of the function like: `function [A, B] = f1(x, y, z)` , instead of requiring us to use `return` at the end of the function to return the results.

That is something of an oddball syntax in Matlab, which is different from any other programming language I’ve used and one I’ve never understood the attraction of. Naturally tastes vary but I’m confident that this is never going to be considered based on [PSA: Julia is not at that stage of development anymore](https://discourse.julialang.org/t/psa-julia-is-not-at-that-stage-of-development-anymore/44872).

---

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [October 18, 2021, 6:24pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/6 "2021-10-18T18:24:04Z")

</div>

I just tested sort(A, dims=1). All rows are mismatched now. Be very careful about using it.

A =  
8 8 6  
4 8 7  
3 7 3  
10 10 1  
9 5 5

sort(A, dims=1) gives me the below:  
3 5 1  
4 7 3  
8 8 5  
9 8 6  
10 10 7

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [October 18, 2021, 6:31pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/7 "2021-10-18T18:31:08Z")

</div>

> [@leon](#):
>
> `function [A, B] = f1(x, y, z)`

@GunnarFarneback I’m curious, this is proper syntax in Matlab? What does it mean?

---

<div class="post-metadata">

**Author:** ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)\
**Post date:** [October 18, 2021, 6:35pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/8 "2021-10-18T18:35:22Z")

</div>

From [matlab’s webpage](https://www.mathworks.com/help/matlab/ref/function.html):

> `function [y1,...,yN] = myfun(x1,...,xM)` declares a function named `myfun` that accepts inputs `x1,...,xM` and returns outputs `y1,...,yN` . This declaration statement must be the first executable line of the function. Valid function names begin with an alphabetic character, and can contain letters, numbers, or underscores.

So in their example:

```julia
function [m,s] = stat(x)
    n = length(x);
    m = sum(x)/n;
    s = sqrt(sum((x-m).^2/n));
end

```

[m,s] is a way of indicating which of variables in the body of the function should be returned to the caller.  
I always found this Matlab syntax ugly.

---

<div class="post-metadata">

**Author:** ![StevenWhitaker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevenwhitaker/32/9749_2.png) [@StevenWhitaker](https://discourse.julialang.org/u/StevenWhitaker)\
**Post date:** [October 18, 2021, 6:38pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/9 "2021-10-18T18:38:54Z")

</div>

It’s used when defining functions to specify what variables are returned.

In MATLAB:

```matlab
function [A, B] = f1(x, y, z)

A = % something
B = % something else

end % no return statement, A and B are returned

```

In Julia:

```julia
function f1(x, y, z)

    A = # something
    B = # something else
    return (A, B)

end

```

I think it’s appealing to see both the function signature and what it returns in one line (particularly when more descriptive names are used than just `A` and `B`). Many people do this in docstrings in Julia, e.g., `f1(x, y, z) -> A, B`, or something similar.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [October 18, 2021, 6:55pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/10 "2021-10-18T18:55:55Z")

</div>

> [@leon](#):
>
> I just tested sort(A, dims=1). All rows are mismatched now. Be very careful about using it.

`sort(A, dims=1)` sorts each column separately; it is _not_ equivalent to Matlab’s `sortrows`. The closest analogue of `sortrows(A)` from Matlab is `sortslices(A, dims=1)` in Julia.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [October 18, 2021, 6:58pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/11 "2021-10-18T18:58:26Z")

</div>

Aside from the wonderful suggestions of the community, I’ve moved the thread out out “Internals & Design” to “General Usage”, since most of the questions in your list are already quite possible, except that they use different syntax than Matlab. To that regard, please note that the general feel of julia is done and probably won’t change much in the feature (though genuinely new feature requests are of course still welcome!) 🙂

Also, see this thread for a bit more info about this:

> [@PSA: Julia is not at that stage of development anymore](https://discourse.julialang.org/t/psa-julia-is-not-at-that-stage-of-development-anymore/44872):
>
> You heard about this brand new exciting programming language called Julia and have some suggestions for how it should work. Wonderful! We’re happy to have you here and help you learn the language and listen to your ideas! However, please be aware that “new” is a relative term. Yes, Julia is newer than, say, C, which was first created in 1972 and standardized in 1989. It is not, however, new in the sense that it is still being freely designed and changed in arbitrary ways. Julia development start…

---

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [October 18, 2021, 7:01pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/12 "2021-10-18T19:01:28Z")

</div>

What exactly is the difference between

> [@lmiq](#):
>
> `A .> 0.5 .&& B .> 0.5`

and

> [@lmiq](#):
>
> `(A .> 0.5) .& (B .> 0.5)`

if any?

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [October 18, 2021, 7:15pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/13 "2021-10-18T19:15:49Z")

</div>

The precedence of the operators, importantly, in this case:

```julia
julia> 2 > 1 && 4 > 3
true

julia> 2 > 1 & 4 > 3
false

julia> (2 > 1) & (4 > 3)
true

```

(`&` and `&&` are not the same thing)

---

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [October 18, 2021, 7:19pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/14 "2021-10-18T19:19:46Z")

</div>

The one in the middle is so confusing. How come the result is false?

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [October 18, 2021, 7:22pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/15 "2021-10-18T19:22:07Z")

</div>

It checks `1 & 4` first, and it is a [Bitwise operation - Wikipedia](https://en.wikipedia.org/wiki/Bitwise_operation#Bitwise_operators), which returns `0` in this comparison. You get the expected `and` and `or` behavior only if comparing to booleans (which is what the parenthesis guarantee there).

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 18, 2021, 7:29pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/16 "2021-10-18T19:29:47Z")

</div>

> [@StevenWhitaker](#):
>
> ```julia
> function f1(x, y, z)
> 
> A = # something
> B = # something else
> return (A, B)
> 
> end
> 
> ```

I should point out that you can write `return A,B` or just

```julia
A, B

```

if the OP dislikes `return` keyword so much.

---

<div class="post-metadata">

**Author:** ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)\
**Post date:** [October 18, 2021, 8:03pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/17 "2021-10-18T20:03:44Z")

</div>

The syntax closest to Matlab’s `[a,b] = f(x,y)` is probably

```julia
julia> f(x,y) = (2x+y, 4y^x)
f (generic function with 1 method)

julia> (a,b) = f(2,3)
(7, 36)

```

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [October 18, 2021, 8:45pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/18 "2021-10-18T20:45:05Z")

</div>

Well, yes, but this wasn’t about calling a function but defining it.

---

<div class="post-metadata">

**Author:** ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)\
**Post date:** [October 18, 2021, 9:26pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/19 "2021-10-18T21:26:59Z")

</div>

I see. OP wants

```julia
function [a,b] = f(x,y)
    a = 2x+y
    b = 4y^x
end

```

Not an improvement, IMHO.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [October 18, 2021, 9:35pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/20 "2021-10-18T21:35:32Z")

</div>

In Matlab, an array of objects is returned: hence `[a, b] = ...`. In Julia, a tuple is returned.  
So it would read `(a, b) <- f(x) = (x, 2*x)`, perhaps?

I do appreciate the information available from the listing of the arguments in the place where the function begins to be defined. However, in Matlab this is then spoiled immediately since the named outputs can be assigned value _anywhere_ inside the function! Not easy to read.

[Next page](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987.md?page=2)
