Julia: don't show display for (nothing, nothing...)

Created on 4 Dec 2018  路  2Comments  路  Source: JuliaLang/julia

Would be consistent to ignore printing result tuple (nothing, nothing,...) the same way the result nothing is not written to the REPL. Occurs always when broadcasting to functions returning nothing.
If you give me hint which of show or display should be specialized for NTuple{Nothing}, I'll fill a PR.
MWE:

foo(x) = println("foo $x");nothing
bar(a...) = foo.(a)
bar(1,2,3,4)

foo 1
foo 2
foo 3
foo 4
(nothing, nothing, nothing, nothing)

foo(1)
foo 1

Most helpful comment

The singleton nothing is special because it is what is returned when a function doesn't return "anything" (like print) so it would be a bit spammy to always show it in the REPL (but it has been considered: https://github.com/JuliaLang/julia/pull/26209). In my opinion, doing the same for a tuple of noting seems taking it a bit too far. If you want to broadcast on something that returns nothing for its side effect it is typically better to use foreach or something since then you don't have to form any result at all.

All 2 comments

The singleton nothing is special because it is what is returned when a function doesn't return "anything" (like print) so it would be a bit spammy to always show it in the REPL (but it has been considered: https://github.com/JuliaLang/julia/pull/26209). In my opinion, doing the same for a tuple of noting seems taking it a bit too far. If you want to broadcast on something that returns nothing for its side effect it is typically better to use foreach or something since then you don't have to form any result at all.

Not to be brusque, but we're not doing this.

Was this page helpful?
0 / 5 - 0 ratings