gpt4 book ai didi

clojure - repl/source 函数在 Clojure 中不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 18:48:34 25 4
gpt4 key购买 nike

我正在尝试使用文件而不是 REPL。

这是我的 clj 文件:

tests.my-clj-file.clj

(ns tests.my-clj-file
(:require [clojure.repl :as repl]))

(defn my-fn
[]
1)

(println (repl/source my-fn))


输出是:

找不到来源

最佳答案

只能从磁盘上的变量中读取源代码。

因此,如果您评估了缓冲区,它会加载到 REPL 中,并且您无法使用 source 查看源代码。

完成阅读源代码的一种方法是将 my-fn 放在另一个文件中(例如,/my_other_clj_file.clj):

(ns my-other-clj-file)

(defn my-fn
[]
1)

不计算缓冲区。

然后转到 /tests/my_clj_file.clj 并评估:

(ns tests.my-clj-file
(:require [clojure.repl :as repl]
[other-file :refer [my-fn]))

(println (repl/source my-fn))

这确实正确地打印了源代码。

(defn my-fn
  []
  1)
nil

关于clojure - repl/source 函数在 Clojure 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41247416/

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