Fork me on GitHub
Jim Newton09:09:38

A long time ago I used lein to create my project which I've been developing for several months. It created the files in the project which I just used as a template but didn't understand on day 1. How when I look at the main ns declaration, I wonder whether the form (:gen-class) needs to be removed. What purpose does it serve?

(ns clojure-rte.core
  (:require [clojure.set :refer [union]]
            [clojure.pprint :refer [cl-format]]
            [ :refer [cl-cond]]
            [clojure-rte.util :refer [with-first-match call-with-collector
                                      visit-permutations rte-constantly rte-identity
                                      print-vals sort-operands member]]
            [clojure-rte.type :as ty]
            [clojure-rte.dfa :as dfa ]


if you don't aot compile, perhaps it is not necessary. this page might have some useful details:

Jim Newton11:09:55

does :gen-class simply allow me to define a function named -main which is then automatically called whenever the class is loaded?


No, it compiles a class with a static method named main (the - is the default prefix)


There is no automatic anything


When Java runs, it needs a class with a staric main to invoke


So :gen-class + a compile can give you a Java main entry point


Or you can just use clojure.main for the same purpose - it knows how to call the -main method on a Clojure ns (compiled or not)

Jim Newton14:09:42

what does a "Java main entry point" do? is that the function which is automatically run when java is started from the unix command line?


Yes - you start Java with a class name and it loads that class and invokes itโ€™s static main method

๐Ÿ‘ 1
Jim Newton14:09:34

And I also see that in cursive, there is a green play triangle if there is a -main method and :gen-class has been specified.

Jim Newton14:09:23

That's pretty useful actually ๐Ÿ™‚


In fact, that will be there even if gen-class is not specified. From my understanding of this project, I think you can remove the :gen-class safely.

๐Ÿ‘ 1
Michael W14:09:41

G'morning. Is there any way to add middleware to the nrepl that cursive sets up, when you choose the nrepl option for your repl configuration?

Michael W15:09:01

Found an answer. Create .nrepl.edn in the root of your project with middleware specified like this:

{:middleware [vlaaad.reveal.nrepl/middleware]}


That is the correct answer!