Reputation: 12803
I am sharing a namespace among all my ring routes in order to keep each route in its own file, so I have a file routes/core.clj
that contains:
(ns test-proxy.routes.core)
;; Some utility functions
Then I start each route handler file like this:
(in-ns 'test-proxy.routes.core)
;; rest of the code
When I start the server, it works perfectly.
But when I make a change in any of the files and reload the page in the browser, I get the following error:
Caused by: java.lang.Exception: Found lib name 'test-proxy.routes.core'
containing period with prefix 'quote'. lib names inside prefix lists
must not contain periods
If I restart the server manually (lein ring server
), all works as expected again, but as soon as I make another change in the code base, it fails with the same error. It definitely looks related to the way I'm using namespaces, but what gets me is that it works without a problem when I restart the server.
If I unquote the namespace to (in-ns test-proxy.routes.core)
like the error seems to suggest, the server doesn't even start:
Syntax error (ClassNotFoundException) compiling at (diplomat/routes/docs.clj:1:1).
test-proxy.routes.core
Upvotes: 0
Views: 78
Reputation: 29984
in-ns
is only meant to be used when at the REPL.
It is fine to divide up your functions any way you want. Just use the fully-qualified name like some.ns.of.mine/my-fn
when you reference the function from any other namespace.
Of course, you can always use a namespace alias like:
(ns some.other.ns.of.mine
(:require [some.ns.of.mine :as snom])) ; define namespace alias
....
(snom/my-fn ...) ; invoke the fn
Be sure to also see How to ns
Upvotes: 1