2

I have a dictionary of words stored in a vector in one ns (ns dictionary.core) and I want to have access the vector in another namespace, for example, (ns clojure-project.core) How should I do it? I have been researching the concept of namespaces for some time and I am still confused as to how I can "import" variables defined in another file into my current project.

1 Answer 1

3
(ns clojure-project.core
  (:require [dictionary.core :as dict]))

(defn choose-a-word []
  (rand-nth (dict/words)))

Namespace declarations have many options, so it can be very confusing! Limiting yourself to the above form is in my opinion good style.

Sign up to request clarification or add additional context in comments.

9 Comments

I keep getting this error: java.io.FileNotFoundException: Could not locate dictionary/core__init.class or dictionary/core.clj on classpath. This is what my namespace looks like: (ns akarify.core (:require [clojure.string :as str]) (:require [dictionary.core :as dict]))
Is there a file under src/dictionary/core.clj? Happy to take a look at a github repo if that helps?
github.com/p-adams/dictionary It is a little disorganized as I just created the repo. core.clj and the corpus file are the files for my project.
Seems a bit confusing. Do you want to use akarify or dictionary as package names? Stick to just one. Then in the package you can have core and corpus. So you might end up with dictionary.core requiring dictionary.corpus.
Hi Mahmud, You need your .clj files to be in a src directory. Also the dictionary.core namespace must be in a file under src/dictionary/core.cljs (not in corups like it is now).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.