The current Julia REPL behaves like MATLAB’s Command Window, that’s, it displays the output by default unless a line is terminated with a semi-colon ;
(except inner-lines). Python’s REPL, on the other hand, doesn’t show the output by default for any line containing the =
sign. I find the latter to be much cleaner (no more ;
scattered everywhere and less cluttered with intermediate results of big objects) and consistent with other IDEs.
My question is can I customize my Julia REPL to behave like Python’s and get rid of these semi-colons? Also, what is your opinion about making that the default for Julia REPL?
1 Like
That’s not a property of Python’s REPL, it’s a property of the Python language: assignment operations don’t produce a value. They later introduced the :=
assignment expression which does produce values, but it was too late to change =
. IPython worked around this and added an option to display assignment results.
In contrast, in Julia, an assignment has a value equal to its right hand side. That’s why it displays in the REPL — the same as any other expression that returns a value.
That being said, it’s pretty easy to suppress this if you want. Just add the following to your ~/.julia/config/startup.jl
file:
function _suppress_assignment_printing(ex)
if Meta.isexpr(ex, :toplevel) && Meta.isexpr(ex.args[end], :(=), 2)
return Expr(:toplevel, ex.args..., nothing)
else
return ex
end
end
import REPL
if isdefined(Base, :active_repl_backend)
pushfirst!(Base.active_repl_backend.ast_transforms, _suppress_assignment_printing)
else
pushfirst!(REPL.repl_ast_transforms, _suppress_assignment_printing)
end
15 Likes
Thank you very much, it worked great.