2014-03-29 54 views
4

我試圖在2個文件分割代碼,每個都有它自己的命名空間。在此之後tutorialClojure的要求命名空間:「不知道如何從創建ISEQ:clojure.lang.Keyword」

但我得到這個錯誤: 異常在線程「主」 java.lang.IllegalArgumentException異常:不知道如何從創建ISEQ:clojure.lang.Keyword

我想這是因爲被包含的命名空間無法正確識別。

主文件:

(ns mytest2.handler 
    (:use compojure.core) 
    (:require [compojure.handler :as handler] 
      [compojure.route :as route] 
      [mytest2.views :as foo] ;<-- line causing error 
      [hiccup.core :refer (html)]) 
) 



(defn layout [title & content] 
    (html 
    [:head [:title title]] 
    [:body content])) 

(defn main-page [] 
    (layout "My Blog" 
    [:h1 "My Blog"] 
    [:p "Welcome to my page"])) 

(defroutes app-routes 
    (GET "/" [] (main-page)) 
    (route/resources "/") 
    (route/not-found "Not Found")) 

(def app 
    (handler/site app-routes)) 

; (println (seq (.getURLs (java.lang.ClassLoader/getSystemClassLoader)))) 

第二個文件:

(ns mytest2.views 
    :require [hiccup.core :refer (html)] 
) 

(defn layout [title & content] 
    (html 
    [:head [:title title]] 
    [:body content])) 

(defn main-page [] 
    (layout "My Blog" 
    [:h1 "My Blog"] 
    [:p "Welcome to my page"])) 

(注意我複製的功能從mytest2.views在mytest2.handler測試他們不應該在mytest2。 .handler)。文件

路徑:

/mytest2/src/mytest2/handler.clj

/mytest2/src/mytest2/views.clj

(其中第一mytest2是該項目的名稱,第二個是lein自動創建的路徑的一部分)。

正如你在第一個文件中看到我打印的類路徑,以驗證/ mytest2/src目錄/ mytest2包括/,是的這是。

+1

除了@ N2O的答案下面,不應該被稱爲符號HTML是[],而不是()?像'[hiccup.core:參閱[HTML]]' – georgek

+1

@georgek兩種形式都相等的編譯器,但'[]'是常規的。 –

回答

6

你錯過了一些括號內的原代碼

; wrong 
(ns mytest2.views 
    :require [hiccup.core :refer [html]]) 

只是有一對括號缺少的。在你的主文件中做:

; Done right! 
(ns mytest2.views 
    (:require [hiccup.core :refer [html]])) 

我不熟悉Compojure,所以我不知道你需要什麼。但是您需要在:require附近添加支架。

相關問題