It should take a while to run, as it will download some resources it needs the first time. If it completes successfully, you are golden! It is the official way to run Clojure applications. Many people are using it now instead of Leiningen. However, Leiningen is still very popular and all of the courses here on PurelyFunctional.
You won't need it for the courses here, but it is a good idea to install it. Homebrew is a package manager for macOS. It is a common tool for developers to use on Macs. Type the following command to update the Homebrew package repository. If it looks like it ran, you're good to move onto the next step.
If the system complains that the brew command is not found , then you will need to install Homebrew. To do that, execute the following command:. This is a text-based interface to talk to your computer. In Ubuntu you can open it by clicking "Dash Home" and typing Terminal.
It may say something like " -bash: java: command not found ", or it may suggest a package to install. Ignore it. In either case, Java is not installed on your system, and we will need to install it. It may output a few lines saying what Java version is installed. The first line will indicate the version of Java. If the version starts with a "1. So if it's "1. It may not have the "1. For instance, it may say "java version In that case, that's Java We need Java 11, so if the number is less than 11, we need to upgrade.
If you have Java 11 or higher, you can move on to installing Leiningen. We have some commands to run in the terminal. If we had students, I might have come to a different conclusion. This should be easy enough just following the official instructions.
My LAs have already had success installing Clojure on Windows using the official instructions. LA Vraj and a student whose name I forget, sorry! I officially recommend Cursive for a cross-platform, fully-featured Clojure environment. We should get an error message at the bottom of the emacs window complaining that clojure can't find parse-args. Let's try to fix the exception by opening core. This time it will succeed, so try running the tests with C-c C-t t i. Whoops, our keys are just strings with the dashes still in place.
We need to strip those off and turn them into keywords:. And re-running the tests in the test buffer we are all happy. If we had multiple test files we can run them all from the CLI using:. Re-running all the tests from Leiningen can be a good sanity check before you wrap up work on a feature or branch since there are some cases where developing from a REPL can give misleading results.
For instance, if you delete a function definition but still call it from other functions, you won't notice until your process is restarted. So that is an extremely simple example of a workflow using Emacs with clojure-mode and cider-test.
One thing we haven't looked at is how useful having an open running REPL in Emacs can be for development. If you still have your project open, split the window C-x 2 horizontally or C-x 3 vertically in two so you have the core. Let's say you are editing the core. Looking at parse-args you have decided you want to pull out the anonymous function to be a named function keywordize. You now have access to the functions in this namespace that were defined when you compiled the file.
Try it:. Now we have a couple of options, we could re-compile the whole file again C-c C-k or we could evaluate each function on its own by going to the end of the s-exp and using C-x C-e i. Now switching back to the core. The ability to continually change the code and play around with it is one of the things that makes Emacs and a lisp a great combination for development. If you find yourself wanting to repeat a command you just typed at the REPL, you can use M-p scroll back through history and M-n to go forwards.
A handy clojure function to use in the REPL is clojure. However there is a shortcut C-c C-d d when your cursor is over a function name. This will show the Clojure or Javadoc doc in a new window. If instead you want to jump to the source of the function you can use M-. This works on your own functions as well as those which come from third-party libraries. Use M-, to pop the stack and return to where you were.
0コメント