在julia中使用带引号的表达式和数组

在julia中使用带引号的表达式和数组,julia,julia-jump,Julia,Julia Jump,我在处理在某个点上索引的数组与在某个点上索引的数组之间的差异时遇到了一些问题。在引用表达式中,该点上的项可以通过以下简单示例看到: julia> A=[:(2+3),:(4),:(9-8)]; julia> t=A[1]; julia> eval(quote @show isequal($A[1],$t) @show $A[1] @show $t end) isequal((Any[:(2 + 3),4,:(9 - 8)

我在处理在某个点上索引的数组与在某个点上索引的数组之间的差异时遇到了一些问题。在引用表达式中,该点上的项可以通过以下简单示例看到:

julia> A=[:(2+3),:(4),:(9-8)];
julia> t=A[1];
julia> eval(quote 
       @show isequal($A[1],$t)
       @show $A[1]
       @show $t
       end)
isequal((Any[:(2 + 3),4,:(9 - 8)])[1],2 + 3) = false
(Any[:(2 + 3),4,:(9 - 8)])[1] = :(2 + 3)
2 + 3 = 5
5
我需要通过编程访问
A
的索引,因此我不能简单地将
t
用于我的应用程序。所以,像这样的事情是行不通的:

julia> A=[:(2+3),:(4),:(9-8)];

julia> eval(quote
       for i in 1:2
       @show $(A[i])
       end
       end)
ERROR: UndefVarError: i not defined

但是,为了使我的应用程序能够运行,我需要一些东西(可能是一个临时变量,我尝试了但没有成功…)来等于
t
。此外,不幸的是,我不能只使用
eval
。非常感谢你的帮助

您需要插入所有
$(A[1])
,而不是像现在一样在
$A

eval(quote
          @show isequal($(A[1]),$t)
          @show $(A[1])
          @show $t
      end)
isequal(2 + 3, 2 + 3) = true
2 + 3 = 5
2 + 3 = 5
5

谢谢你的评论。问题是,如果这是在循环中进行的,并且
1
是某个变量,那么它将不可用:julia>eval(在1:2@show$(a[i])end end end end end中引用i)ERROR:UndefVarError:i not defined您能更新示例以实际显示问题吗?