从lein repl中查找命名空间

时间:2013-10-07 20:07:13

标签: web-applications clojure clojurescript pedestal

编辑:已解决 我的问题来自两件事 - 我在defmacro某处出现语法错误。我删除它并编写了一个小函数,然后我可以访问(仅在重新启动repl之后)。最重要的第二个问题是,我不知道需要重新启动repl以识别我所做的任何更改。如果没有下面给出的具体答案,我们永远不会想到这一点=)。

我一直在使用github上的基础教程,它建议通过repl测试一些东西 - 我的问题是我找不到我感兴趣的命名空间/宏或函数。

user=> (require '(junkyard-client.html-templates))
nil
user=> (def t (junkyard-client-templates))

user=> CompilerException java.lang.RuntimeException: Unable to resolve symbol: 
  junkyard-client-templates in this context, compiling:
  (C:\Users\Ben\AppData\Local\Temp\form-init3290053673397861360.clj:1:8)

我在语法上尝试了其他的东西,例如(require'junkyard-client.html-templates)。 这是基座教程中的v2.0.10:https://github.com/pedestal/app-tutorial/wiki/Slicing-Templates

编辑:这就是我想要的目标

(ns junkyard-client.html-templates
  (:use [io.pedestal.app.templates :only [tfn dtfn tnodes]]))

(defmacro junkyard-client-templates
  []
  {:junkyard-client-page (dtfn (tnodes "junkyard-client.html" "hello") #{:id})
   :other-counter (dtfn (tnodes "tutorial-client.html" "other-counter") #{:id}
  })

问题阶段 https://github.com/Sammons/clojure-projects/tree/d9e0b4f6063006359bf34a419deb31a879c7a211/pedestal-app-tutorial/junkyard-client

解决了阶段

1 个答案:

答案 0 :(得分:1)

require使命名空间在当前命名空间中可用,但不会使符号直接可用。除非使用:referuse

,否则您仍需要对符号进行命名空间限定
(require '[junkyard-client.html-templates])

(def t (junkyard-client.html-templates/junkyard-client-templates))

为方便起见,最好为命名空间设置别名或引用您正在使用的特定符号。

<强>别名:

(require '[junkyard-client.html-templates :as templates])

(def t (templates/junkyard-client-templates))

<强>参见:

(require '[junkyard-client.html-templates :refer [junkyard-client-templates]])

(def t (junkyard-client-templates))

注意: require:refer通常优先于use

相关问题