Clojure working with files


















Create a deps. You will see messages about a library being downloaded the first time you use a dependency. You can use the same process to add other libraries to your deps. Soon you will want to build and save your own code that makes use of these libraries. Create a new directory and copy this deps. By default, the clj tool will look for source files in the src directory. This program has an entry function run that can be executed by clj using -X :.

You might decide to move part of this application into a library. The clj tool uses local coordinates to support projects that exist only on your local disk. The final structure will look something like this:. Under time-lib, use a copy of the deps. It would be great to share that library with others. You can accomplish this by pushing the project to a public or private git repository and letting others use it with a git dependency coordinate.

Then go to a public git repository host like GitHub and follow the instructions for creating and publishing this git repository. Finally, modify your app to use the git dependency instead. Now you can run the app again, making use of the shared git repository library. As your program gets more involved you might need to create variations on the standard classpath. The Clojure tools supports classpath modifications using aliases, which are parts of the deps file that are only used when the corresponding alias is supplied.

Some of the things you can do are:. Typically, the project classpath includes only the project source, not its test source by default. You can add extra paths as modifications to the primary classpath in the make-classpath step of the classpath construction. To do so, add an alias :test that includes the extra relative source path "test" :. Apply that classpath modification and examine the modified classpath by invoking clj -A:test -Spath :.

You can extend the :test alias in the previous section to include the cognitect-labs test-runner for running all clojure. When you save the file, SPC f s you are prompted to create any directories required. When you create a new file for a namespace that has multiple words, then convention is to use kebab-case to separate the words.

However, due to a limitation with the Java Virtual Machine class loader, filenames should not include dashes, rather they should use underscore characters instead.

So when you create a new file for a kebab-case namespace, Spacemacs will ask if you want to change the filename to use underscores for the dashes in the name. Say yes to keep the Java class loader happy. When creating a new file in a new directory, you can simply type in the full path and file name and Spacemacs will prompt you to confirm the creation of the new directory and the file name. The swank-related answer I linked to in the last parenthetical remark has details on how to set up swank with the correct classpath from within Emacs.

Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Clojure load files Ask Question. Asked 11 years, 7 months ago. Active 11 years, 7 months ago. Viewed 3k times. How do you set up a simple clojure project? So8res So8res 9, 9 9 gold badges 49 49 silver badges 84 84 bronze badges. Add a comment. Active Oldest Votes. Alex B Alex B 78k 39 39 gold badges silver badges bronze badges.

It's working now. However, since your question is "how to set up a simple Clojure project", the following is a better start: Go to GitHub and grab Leiningen.



0コメント

  • 1000 / 1000