在 REPL 中调试或运行 julia 代码时,我通常会看到显示 ... at ./REPL[161]:12 [inlined]...
的错误消息。 .号码161
表示 161-th
我想在 REPL 中进行评估。所以我的问题是我们能否在 julia 的提示中显示这个数字,即 julia [161]>
而不是 julia>
?
最佳答案
Julia 的优势之一是其超强的灵活性。这在 Julia 0.7(夜间版)中非常容易。
julia> repl = Base.active_repl.interface.modes[1]
"Prompt(\"julia> \",...)"
julia> repl.prompt = () -> "julia[$(length(repl.hist.history) - repl.hist.start_idx + 1)] >"
#1 (generic function with 1 method)
julia[3] >
julia[3] >2
2
julia[4] >f = () -> error("e")
#3 (generic function with 1 method)
julia[5] >f()
ERROR: e
Stacktrace:
[1] error at .\error.jl:33 [inlined]
[2] (::getfield(, Symbol("##3#4")))() at .\REPL[4]:1
[3] top-level scope
您只需要将前 2 行放到您的
~/.juliarc
上并享受~由于 julia 0.7 之后 REPL 有几个变化,这些代码在旧版本中不起作用。
编辑:嗯,实际上需要更多的努力才能让它在
.juliarc.jl
中工作.试试这个代码:atreplinit() do repl
repl.interface = Base.REPL.setup_interface(repl)
repl = Base.active_repl.interface.modes[1]
repl.prompt = () -> "julia[$(length(repl.hist.history) - repl.hist.start_idx + 1)] >"
end
关于julia - 更改 julia 提示以包含评估编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48055583/