Fork me on GitHub
#cursive
<
2020-09-19
>
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]]
            [clojure-rte.cl-compat :refer [cl-cond]]
            [clojure-rte.util :refer [with-first-match call-with-collector
                                      fixed-point
                                      visit-permutations rte-constantly rte-identity
                                      partition-by-pred
                                      print-vals sort-operands member]]
            [clojure-rte.type :as ty]
            [clojure-rte.dfa :as dfa ]
            [clojure-rte.rte]
            [clojure-rte.memoize]
            [clojure-rte.api]
            [clojure-rte.type-extend]
            )
  (:gen-class))

sogaiu09:09:34

if you don't aot compile, perhaps it is not necessary. this page might have some useful details: https://clojure.org/reference/compilation

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?

Alex Miller (Clojure team)11:09:04

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

Alex Miller (Clojure team)11:09:29

There is no automatic anything

Alex Miller (Clojure team)11:09:30

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

Alex Miller (Clojure team)11:09:59

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

Alex Miller (Clojure team)11:09:12

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?

Alex Miller (Clojure team)14:09:13

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

๐Ÿ‘ 3
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 ๐Ÿ™‚

cfleming02:09:21

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.

๐Ÿ‘ 3
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]}

cfleming02:09:24

That is the correct answer!

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]}