Clojure requires a namespace: "I don't know how to create ISeq from: clojure.lang.Keyword"

I am trying to split the code into 2 files, each with its own namespace. Following this tutorial .

But I get this error: Exception in thread "main" java.lang.IllegalArgumentException: I don't know how to create ISeq from: clojure.lang.Keyword

I think this is because the included namespace is not recognized properly.

Main file:

(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))))

Second file:

(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"]))

(note that I copied the functions from mytest2.views to mytest2.handler for testing. They should not be in mytest2.handler).

File paths:

/mytest2/src/mytest2/handler.clj

/mytest2/src/mytest2/views.clj

(where the first mytest2 is the name of the project, and the second is the path automatically created by the lane).

, , , /mytest2/src/mytest2/, , .

+4
2

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

. :

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

Compojure, , . :require.

+6

- :refer :all Clojurescript, , -, .

+11

Source: https://habr.com/ru/post/1534037/


All Articles