2013-10-07 51 views
1

編輯:已解決 我的問題來自兩件事 - 我在defmacro某處出現語法錯誤。我刪除它,並寫了一個小功能,然後我可以訪問(只有在重新啓動repl後)。最大的第二個問題是,我不知道repl需要重新啓動才能識別我所做的任何更改。如果沒有下面給出的具體答案,將永遠不會得出這個結論=)。從lein 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) 

我嘗試過其他語法的東西,比如(需要'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

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

+0

命名空間仍然沒有解決? user =>(需要'[junkyard-client.html-templates:as模板]) user =>異常命名空間'junkyard-client.html-templates'not found clojure.core/load-lib(core.clj: 5380) 我一定在做一些奇怪的事情。我開始從根目錄(垃圾場客戶端)的repl,我可以成功(開始)沒有問題。謝謝你的回答,因爲它幫助我更清楚地看到事情應該如何工作。 – Catalyst

+0

嘗試使用'project.clj'文件在目錄內運行'lein repl',以便獲取您的依賴關係和配置。 – Jared314

+0

這就是我從哪裏運行,它掛鉤到項目並加載依賴關係 – Catalyst