【问题标题】:Unsupported `const` declaration on local variable in JuliaJulia 中的局部变量不支持“const”声明
【发布时间】:2021-08-22 07:16:49
【问题描述】:

在 Julia 中,我定义了一个函数,它接受一些参数 x,y,z,它们中的每一个都不会通过函数内部的过程进行更改。为了优化我的程序,我打算将x,y,z 设为const。我是这样做的:

function myFunc(x,y,z)
  const x = x; const y = y; const z = z;
  
  # algorithm using x,y,z
  # ...
  # ...

end

但是,我在下面发现了一个错误:

syntax: unsupported `const` declaration on local variable around In[55]:36

怎么了?

任何信息将不胜感激。

【问题讨论】:

    标签: function variables types constants julia


    【解决方案1】:

    目前不支持它,并且出于性能原因不应该需要它(尽管它对于捕获意外变异的参数可能很有用)。更多讨论请参见https://github.com/JuliaLang/julia/issues/5148

    【讨论】:

    • 谢谢。我理解它在 Julia 的本地范围内使用时,使用常量不再与性能有关。
    • 即使允许本地const,代码试图使const变量与输入参数共享它们的名称不是问题吗?
    • 我认为它只是新的x,即const
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-12
    • 2021-11-16
    • 1970-01-01
    • 2014-05-10
    • 2021-06-03
    相关资源
    最近更新 更多