gpt4 book ai didi

Julia 宏可能会以不同的方式对待变量和文字吗?

转载 作者:行者123 更新时间:2023-12-01 17:33:23 24 4
gpt4 key购买 nike

各位 Julia 用户,大家好,

为什么会这样

using HDF5, JLD
s = "It would take me 48 hours to recompute this."
filename_no_ext = "eric_demo_file"
@save filename_no_ext
readdir()
@load "eric_demo_file"

评估与此不同?

using HDF5, JLD
s = "It would take me 48 hours to recompute this."
filename_no_ext = "eric_demo_file"
@save filename_no_ext
readdir()
@load filename_no_ext

最佳答案

与函数相比,宏是非常不同的野兽。区别之一是他们不评估他们的论点:http://docs.julialang.org/en/latest/manual/metaprogramming/#macro-invocation

It is important to emphasize that macros receive their arguments as expressions, literals, or symbols.

要了解比较 2 个输出的含义(留作练习):

julia> macroexpand(:(@load filename_no_ext))

julia> macroexpand(:(@load "eric_demo_file"))

关于Julia 宏可能会以不同的方式对待变量和文字吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30582880/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com