2016-09-14 113 views
2

我能管端子輸入到正在運行的朱莉婭REPL?朱莉婭 - 管朱莉婭REPL

在終端我可能會創建一個管道

mkfifo juliapipe 

裏面的朱莉婭REPL我試過

connect("juliapipe") 

返回錯誤

ERROR: connect: connection refused (ECONNREFUSED) 

有沒有一種辦法做這個?無論是與命名管道或任何其他方式

+0

否則周圍'的eval一個環路(解析(readline的(F)))'應該基本上從'F'執行語句,它可以是一個命名管道。 –

回答

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但有些類似於你在找什麼。