A Python-like REPL?

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