我可以将终端输入传输到正在运行的Julia REPL吗?
在终端我可能会创建一个管道
mkfifo juliapipe
朱莉娅REPL里面我试过了
connect("juliapipe")
返回错误
ERROR: connect: connection refused (ECONNREFUSED)
有办法做到这一点吗?使用命名管道或任何其他方式
答案 0 :(得分:2)
与@DanGetz建议的一样,一种方法是display(eval(parse(f)))
直到eof(f)
。
例如,给定文件test.jl
:
1 + 1
ans * 3
function f(x)
x ^ x
end
f(3)
println("Hello, World!")
我们可以在REPL中做到
julia> open("test.jl") do f
global ans
while !eof(f)
cmd = parse(f)
println("file> $cmd")
ans = eval(cmd)
if ans !== nothing
display(ans)
println()
end
end
end
file> 1 + 1
2
file> ans * 3
6
file> function f(x) # none, line 3:
x ^ x
end
f (generic function with 1 method)
file> f(3)
27
file> println("Hello, World!")
Hello, World!
这不是一个REPL,但有点类似于你正在寻找的东西。