How can I eval a local variable in Julia

后端 未结 4 1141
太阳男子
太阳男子 2020-12-10 04:00
i = 50
function test()
  i = 10
  eval(:i)
end
test()  # => 50

Why does this evaluate to the global i instead of the local one? Is

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-10 04:36

    Depending on the application, you could eval the entire function to get at the local value of i such as @simonster describes in this answer.

提交回复
热议问题