Last active
August 29, 2015 14:06
-
-
Save josericardo/891fc4219ee899e16e87 to your computer and use it in GitHub Desktop.
How to run a clojure file/script using leiningen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If you’re taking your first steps in the clojure world and just want to try out some commands. Assuming you are using leiningen and have already created a project using lein new, you have two options: | |
1. Fire a REPL | |
That’s easy: | |
$ lein repl | |
The downside of this option is that lein, AFAIK, doesn’t allow us to save the session contents to a file. | |
2. Run a script | |
This is useful specially when you want to have access to the code in a later coding session. This can be achieved in three steps. | |
2.1 create the file under the src folder. For example: src/joyofclojure/xor.clj. | |
2.2 Declare a namespace for the file: | |
(ns joyofclojure.xor) | |
2.3 define a main function, just like you’d do in java, which will serve as your script’s entry point: | |
(defn -main [] ... ) | |
That’s it, now you can run you code via: | |
$ lein run -m joyofclojure.xor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment