gpt4 book ai didi

debugging - 调试 Clojure 函数的推荐方法?

转载 作者:行者123 更新时间:2023-12-04 11:31:03 24 4
gpt4 key购买 nike

我目前的方法:如果我知道某个函数存在错误,我会将它的一部分复制到 REPL 中并评估输出是否符合我的预期。要设置它,我必须将函数的参数定义为虚拟输入。不是非常耗时,但我知道有一种更有效的方法。

有什么建议?

最佳答案

这个宏有用吗?它将 let 变成一系列 defs,以便您可以评估子表达式:

(defmacro def-let
"like let, but binds the expressions globally."
[bindings & more]
(let [let-expr (macroexpand `(let ~bindings))
names-values (partition 2 (second let-expr))
defs (map #(cons 'def %) names-values)]
(concat (list 'do) defs more)))

我在这里写了一个解释:
http://www.learningclojure.com/2010/09/astonishing-macro-of-narayan-singhal.html

关于debugging - 调试 Clojure 函数的推荐方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3792249/

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