当我在repl中定义我的函数时,它按预期工作。当我将它放入命名空间(即我的应用程序)并重新加载repl时,我丢失了关键字上的namespace
组件。我不确定我在这里缺少什么。
;; Repl
(defn repl-keyword-gen [k str] (keyword (name k) str))
(repl-keyword-gen :test "example")
;;=> :test/example
;; App - example.core
(defn app-no-sym-keyword-gen [str] (keyword "test" str))
(defn app-with-sym-keyword-gen [k str] (keyword (name k) str))
(app-no-sym-keyword-gen "example")
;;=> :test/example
(app-with-sym-keyword-gen :test "example")
;;=> :example <----- Not sure about this one right here
非常感谢有关此关键字构建器返回不同结果的原因的见解/解释。
已编辑 - 屏幕截图
答案 0 :(得分:2)
我认为您的环境可能存在问题。
我使用普通的lein run
测试并获得了namespaced关键字:
(ns clj.core
(:require
[tupelo.core :as t]
[clj-time.core :as tm]
))
(t/refer-tupelo)
;; App - example.core
(defn app-no-sym-keyword-gen [str] (keyword "test" str))
(defn app-with-sym-keyword-gen [k str] (keyword (name k) str))
(spyx (app-no-sym-keyword-gen "example"))
(spyx (app-with-sym-keyword-gen :test "example"))
(defn -main [& args]
(println "-main"))
结果:
~/clj > lein run
(app-no-sym-keyword-gen "example") => :test/example
(app-with-sym-keyword-gen :test "example") => :test/example
-main
要使(spyx ...)
部分起作用,您需要在project.clj中使用它:
:dependencies [
[tupelo "0.9.9"]
...