Thursday, August 06, 2020

My Clojure experience

 As I mentioned in this post, I found that Cursive IDE is the recommended way to go and that's what I tried. To be honest, the whole process is not exactly what I would call intuitive. I think the guides I mentioned in my previous post did a pretty good job. Let me summarize a few key features:

1) CursiveIDE is based on IntelliJ so the latter is the one you start. The type of project to add is Clojure->Leiningen (FYI, Leiningen is a build automation tool. I think the name comes from the short story "Leiningen Versus the Ants" Of course, ant refers to the "other" famous tool)


The project name must be all lowercase.

The IDE automatically creates a bunch of files for you. The most important one is probably project.clj. If your code requires importing external modules, you specify the dependency in this file. I found that the REPL that is already running would not "take in" the new dependency so the safest thing to do is to kill the existing REPL and start a new one.

2) The Right-click menu of project.clj has a choice to start your REPL. By default the namespace is <your project name>.core. In fact, Cursive also automatically creates a core.clj file for you.


3) If you want to have code in another <file name>.clj file, you add New Clojure Namespace with <file name>, the namespace would be <project name>.<file name>

4) You can load your current .clj file into the REPL using the right-click menu and then REPL.


5) However, Cursive does not switch namespace automatically. Use the same menu to switch. 

6) You can send a statement in your .clj file to the REPL for execution. Alternatively you can type the statement in the lower REPL window and hit ENTER after the closing ')' (or hit CTRL-ENTER)

BTW, this is the fun project I worked on: calculation of hours of sunlight based on the coordinates of the city and the date.