Additional Clojure Project Source Files

When the lane sets up the project, the core.clj file is created along with other directories and files. I want to know if I can split the contents of core.clj into another source file in

../myproj/src/myproj/

and if so, how to access this data from core.clj.

+4
source share
3 answers

IIRC (I donโ€™t have a project that can be verified), everything in your src/myproj/ is in the 'myproj . Thus, your core.clj file will be in the namespace 'myproj.core . Other files will be in their own namespaces in the namespace 'myproj (for example, 'myproj.other-file for other_file.clj ) and can be pulled into core.clj by doing:

 (use 'myproj.other-file) 

or in ns declaration:

 (ns myproj.core (:use [myproj.other-file])) 
+4
source

You can divide definitions into as many files as you want, although it is idiomatic to place one namespace in one file and vice versa.

See http://clojure.org/libs to specify and upload files and namespaces. Keep in mind that dashes in namespaces are converted to underscores in file names.

+4
source

Leiningen project.clj is to define a var project , which is nothing more than a map with keys representing project parameters (this is an idiom in Clojure to use def [name] to create a var named [name], which is usually a map - the simplest but very useful data structure).

See defaults var in Leiningen 2 source code for default values.

With that said, before you call the defproject macro, you can do whatever you want in project.clj - it's a Clojure script, because your imagination (and getting to know Clojure) is just something that can limit you. In fact, you can do whatever you want with var after creating it. Think of a .clj project as a Clojure application to manage your project.

As an example, before profiles were introduced in Leiningen 2, there was a โ€œtrickโ€ to have one var with common dependencies for dependencies: dependencies and dev-dependencies. Just to warn you again - Leiningen 2 is no longer needed as it offers a profile object. Read Testing your project for several versions of Clojure if you are interested in how it was in the past.

+1
source

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


All Articles