Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lib names inside prefix lists must not contain periods

I am learning clojure now, I wrote a file like this:

;; File ./mycode/myvoc.clj

(ns mycode.myvoc
    (:use 'clojure.java.io)
    (:import (java.io.File)))

; more code here...

this file resides in ./mycode/, when I run REPL, I wanna use the function in myvoc.clj, like this:

user=> (use 'mycode.myvoc)
java.lang.Exception: lib names inside prefix lists must not contain periods (myv
oc.clj:1)

I don't know why. if I change myvoc.clj as :

(ns mycode.myvoc)
;    (:use 'clojure.java.io)
;    (:import (java.io.File)))

It'll be ok but just report no "reader in this context" for I commented the import part.

Could somebody fix this? I alse use require but get the same kind of error.

like image 683
user2545464 Avatar asked Jul 25 '13 09:07

user2545464


1 Answers

You need to remove the quote from your :use clause:

(ns mycode.myvoc
  (:use clojure.java.io)  ; note no '
  (:import java.io.File)) ; extra parens removed here; they do no harm,
                          ; though

'clojure.java.io is shorthand for (quote clojure.java.io), so your original :use clause was

(:use (quote clojure.java.io))

This looks as if you were trying to :use a namespace with a prefix of quote and final segment clojure.java.io. The dots in the latter are the direct cause of the error from the point of view of ns.

Incidentally, it's much more usual to (:require [clojure.java.io :as io]) and then say io/file, io/reader etc. than it is to pull in the entire namespace.

Finally, just to be clear, the quote is necessary when using the function use (like in your (use 'mycode.myvoc) call), as opposed to a :use clause in a ns declaration.

like image 159
Michał Marczyk Avatar answered Nov 08 '22 01:11

Michał Marczyk