【发布时间】:2023-02-08 23:10:53
【问题描述】:
这是一个 Julia 相关的问题。但是为了提供一些上下文,我不是最好的程序员,所以我的 python 工作流程是在函数中编写一些半完整的代码,然后在 pycharm 中调试代码并使用交互式调试控制台帮助我弄清楚如何完成功能。例如
def cartesian_product():
a = ['1', '2', '3']
b = ['a', 'b', 'c', 'd']
# I want to compute the cartesian product of two lists but I don't quite know how
# it's done so I google a bit attach the debugger here and explore the various
# approaches eventually settling with the itertools.product() approach.
return list(itertools.product(a, b))
现在我想知道在 Julia 中使用 visual studio 代码是否有类似的方法?
当我创建半完整的 julia 函数时
function cartesian_product()
a = ['1', '2', '3']
b = ['a', 'b', 'c', 'd']
# attach debugger here and try figure out the rest using the vs code interactive
# debugger
end
这种方法的问题是我无法在调试控制台中创建新变量。可能是因为 julia 是一种编译语言?
例如,如果我在 b 语句处设置断点,变量 a 已加载到内存中,但 b 尚未加载。所以在调试控制台中,我定义了b,就像在 python 调试控制台中一样。但是现在当我尝试引用b时,我得到了一个UndefVarError: b not define
所以我的问题是,如果这种类型的工作流程不可能(即在调试控制台中解决问题),有哪些替代方案?
我试过这些方法:
- 在
.jl文件中编写代码。然后在 REPL 中运行它们——但是当你有很多自定义模块和函数(设置代码)在你感兴趣的代码点之前运行时,这种 get 会很混乱。 - 快速浏览了
revise,但我不认为它完全符合我的要求。我是否只需要接受它并采用不同的编程方法?
【问题讨论】: