Why is this printing to REPL?

Sorry, new to Julia (from Matlab),

If I copy + paste this into the REPL (Julia v1.0.0), no output is printed:

N = 1024;
A = rand(Float64,N,N);
B = rand(Float64,N,N);
ii = 2:N-1;
jj = 2:N-1;
J = zeros(Float64,N,N);
@time @views J[jj,ii] .= A[jj.+1,ii.-1] .- B[jj.-1,ii.+1];

But if I save to a file run via include:

include("C:/my/path/to/why.jl")

It prints the following:

1022×1022 view(::Array{Float64,2}, 2:1023, 2:1023) with eltype Float64:

followed by the contents of the array.

If I put a semicolon after the include statement, e.g. include();, nothing is printed, but it’s not clear to me whether this is expected behavior – I have semicolons everywhere in the included file, so why is anything being printed? Is this negatively affecting performance, even with the include(); version?

The only place where values get printed automatically when not followed by a ; is the REPL (or things that are similar to the REPL like IJulia notebook). This is totally different from the matlab behavior that IMO doesn’t make any sense from a programing language POV and extremely annoy in practice.

This means that the ; in your script is having no effect what so ever on the REPL printing, only what you type in the REPL does. You didn’t have the ; on the include so whatever include returns will be printed.

Yes.

Which have no effect at all.

Because it’s the return value of the include that’s printed, which is the value of the last expression in the file.

No. This is purely a REPL statement behavior and has nothing to do with the behavior and therefore the performance anywhere else.

4 Likes

Thank you.