Fork me on GitHub

I have a namespace with a gen-class function in order to generate a single java class with a static method (something like this: I'm working on a library so I don't want to create an uberjar, but it appears that the only way to get this class in my jar is to add :aot for the namespace in the project.clj, which includes all of the dependencies and transitive dependencies as well. Is there any way to simply generate the one class? If not, is there a best practice for how to handle this?

Alex Miller (Clojure team)04:11:35

you could just write it in Java

Alex Miller (Clojure team)04:11:09

lein knows how to compile and include Java classes already


I have done almost all clojure koans. Can I better do a lot of 4clojure to practice more with clojure or can I try to make a small web app with for example luminus ?


At this point @roelofw I'd recommend doing the 4clojure problems to practice more before you try tackling something like Luminus...


I was thinking about porting a ruby app to clojure with json reponses and maybe some sort of caching


If you want a simple web app "framework", take a look at FW/1 which is what we use at work (it's a small, convention-based wrapper for Ring, Compojure, and Selmer).


@seancorfield so first the 4clojure problems and then luminus ?


@seancorfield looks nice, First I have to find out how boot can be installed. Till now I only have worked with leiningen


Boot is definitely worth learning.


also I do not know if cursive can work with boot


Hmm, no idea. At work we switched from Leiningen to Boot about a year ago as we were finding Leiningen too limiting for the sort of build tasks we needed.


oke, I was thinking about a 2 page web app. where on the first page 10 paintings are seen and on the second page a detail page of a painting is seen


later on I could make pagination to the first page so multiple pages can be seen


the paintings come from a external api with json responses


CIDER (and Emacs) has full support for Boot. I guess I'm a bit surprised other editors don't.


I gather Cursive is somewhat held back by needing to support Java 6 since that's what IntelliJ inflicts on it, at least on Mac?


No idea, I have to ask the maintainer of cursive


Colin is pretty responsive and Cursive is an impressive piece of tech. I know he's frustrated by having to maintain that level of backward compatibility.


Still, if the only consideration is needing a project.clj file, you could create a new FW/1 project via the template and then convert build.boot to project.clj and stay with that 🙂


First trying to make the elementary and easy problems and then look for the web app . Sounds to me like a good plan


(but, yes, you would need the or boot script installed -- it's easier to set up than Leiningen to be honest)


for me it would be boot.exe because I work on Windows 10


@seancorfield thanks a lot for sharing info and make your reccomendation


@roelofw I use Boot on Windows 10 (as well as Mac and Linux).


I'd forgotten it was a .exe file -- usage is pretty seamless across all three platforms.


I must say that the first 14 problems of 4 clojure are dead simple


Can you recommend a json library so I can parse the json response to a clojure object


Cheshire is the gold standard.


FW/1 uses Cheshire automatically (I should have included that with Ring, Compojure, and Selmer above).


oke, I will look at FW/1 in a short time


First trying to do the elementary and easy problems of 4 clojure


@seancorfield thanks a lot for your time


@seancorfield there is no tutorial where a page is made with FW/1 ?


what is FW/1?


Hi, I am trying to create a macro to declare a dynamic var. I am losing the ^:dynamic information and and I don’t know why. Any ideas?

(defmacro declare-dyn [name]
  `(declare ^:dynamic ~name))

(declare-dyn foo)

(binding [foo 42] foo)

CompilerException java.lang.IllegalStateException: Can't dynamically bind non-dynamic var: user/foo


@lboliveira try

(defmacro declare-dyn [name]
  `(declare ~(vary-meta name assoc :dynamic true)))


@moxaj It worked! Thank you 😃


How should I go about making a spec for a joda time? (such as created with (clj-time.core/now))?


I guess... use satisfies? and spec/with-gen and build my own generator. But does one exist already?


@escherize you can use a large-integer* and use from-long: (fmap clj-time.coerce/from-long (large-integer* {:min start-epoch :max end-epoch}))


a minimal version would be (fmap clj-time.coerce/from-long large-integer), but you'll end up with some odd dates

Alex Miller (Clojure team)13:11:01

Another option in 1.9 would be to extend the joda instant to the new Inst protocol. If you do that, then inst? will work and the s/inst-in spec will work

Alex Miller (Clojure team)13:11:31

Date is covered this way and Java 8's Instant


sweet, I didn't know about inst?


Thanks @alexmiller (re: my post on aot last night), as soon as I walked away from my computer I figured I should just write it in java. Just curious, though, is the fact that all of the clojure dependencies of the aot namespace are compiled just an artifact of how lein chooses to handle it or is that an implicit requirement in how gen-class works? Would it theoretically be possible to only compile the gen-class class?


gotcha. thanks.


Does anyone know if Sublime Text or Atom can work with boot. So I can make a app with boot and do boot run without using a external terminal


no assoc-in! for transients?


Is there anything in Clojure resembling Akka and actors yet but more CSP-oriented (distributed, long-running graphs of CSP channels, heavy on queues, backpressure, etc.)? I am aware of Quasar and Pulsar, but at that point I would just use Akka for various reasons. I also know about and use Onyx, but it's not a fit for some of my use-cases. I currently have some form of scale-out via Kafka consumers/producers, but this is only a piece of a larger solution.


how would you convert a string value to a keyword in a nested JSON coming from a server? I'm trying to use clojure.spec, but I'm somewhat confused if I should use a custom conformer. In Prismatic's Schema coercion is kinda obvious, but is it an intended use for clojure.spec?


So I did it like this; is it the correct/intended way?

Alex Miller (Clojure team)16:11:28

the general caveat is: be careful about your use of conformers, particularly in registered specs. You are making decisions for all future consumers of your specs and (like here) potentially throwing away information (there is no way to tell from the conformed value here whether you received a string or a keyword).


some boot expert here : when I do boot run I see this error message :

boot run
        clojure.lang.ExceptionInfo: No such task (run)
    data: {:file
           :line 7}
java.lang.IllegalArgumentException: No such task (run)
          boot.core/construct-tasks  core.clj:  905
                 clojure.core/apply  core.clj:  630
                  boot.core/boot/fn  core.clj:  949
clojure.core/binding-conveyor-fn/fn  core.clj: 1916


My build.boot looks like this :

(def version "0.1.0-SNAPSHOT")

 aot {:namespace   #{'myfw1app.main}}
 pom {:project     'myfw1app
      :version     version
      :description "FIXME: write this!"}
 jar {:main        'myfw1app.main
      :file        (str "myfw1app-" version "-standalone.jar")})

(set-env! :resource-paths #{"src" "resources"}
          ;; the org.clojure/clojure dependency here only affects
          ;; what is bundled in the uberjar via the build task so
          ;; be careful if it is different to the version you have
          ;; configured for Boot!
          :dependencies   '[[org.clojure/clojure "RELEASE"]
                            [framework-one       "RELEASE"]
                                        ; comment this out if you don't want
                                        ; to use http-kit at all:
                            [http-kit            "RELEASE"]])

(deftask build []
  (comp (aot) (pom) (uber) (jar) (target :dir #{"target"})))

(deftask run
  [p port    PORT    int      "the port on which to run the application."
   c config  ARG=VAL {kw str} "the config map for the application."]
  (require '[myfw1app.main :as app])
  ((resolve 'app/start) port config))

(defn- generate-lein-project-file!

  [& {:keys [keep-project] :or {:keep-project true}}]

  (let [pfile (io/file "project.clj")

        pname (or (get-env :project) 'boot-project)

        pvers (or (get-env :version) "0.1.0-SNAPSHOT")

        prop #(when-let [x (get-env %2)] [%1 x])

        head (list* 'defproject pname pvers


                 (prop :url :url)

                 (prop :license :license)

                 (prop :description :description)


the last two I added because I want to work with cursive and boot


alright, I've decided it's high time I learn how to use css. So my goal is to (1) use a css 'pocketbook' (2) work through all the tedious examples, and (3) do everything directly in clojure, instead of writing actual *.css file. On the cljs side, I'm using figwheel + devcards -- what clojure css library should I use to have everything work together nicely?


could anyone give a simple explanation of why boot is so cool nowadays?


it seems ant, or (even worse) setuptools to me


It allows you to write your tasks using clojure code instead of a DSL which is pretty cool. Task writing and composition is pretty easy with it.


I see...


is this one of those situations where "declarative is all nice and all that, but really doesn't match the problem domain" ?


delcarative is fine for simple things


ir breaks when you want to create abstractions


worth pointing out though that you usually need to get to a pretty hefty level of complexity in your build process before lein falls down


as someone writing a forth based interpreter, clearly the solution is to embed a forth interpreter inside lein 🙂


forth is awesome.


concatentative programming ftw.


@seancorfield I have fw/1 with a standard template working


Any examples I can study for controllers and so on ?


@alexmiller I see, thank you!


I’m having a misunderstanding about protocols and records when defining the entities for my system, and was hoping someone could clarify:


Suppose I have two entities A and B that share common traits such as - they have names, unique ids, and perhaps a “status” that might be some map such as {:last-known “” :current- “”}. What I feel like doing (whether its idiomatic or not I’m sure) is defining a “statusable” protocol, and having separate defrecord A and B that implement statusable.


But really that protocol isn’t much of a function, it’s more like a flag demarking “hey I have this object representing a status”.


Is there a better way to defrecord a field that is a map, or a field that points to a map?


Or by definition is a record only a collection of primitive values?


@lwhorton You can have any value in a record field.


I think a protocol for statusable would be reasonable if you require the polymorphism


but if they both use the same key for their status information you don't require the polymorphism


But also, don't shy away from maps. Using records is useful as a performance optimization or to implement existing protocols or Java Interfaces.


Okay, great .. thanks both @bfast @eraserhd. It seems I’m thinking about protocols on the wrong level where a map will just work. Do you have an example @eraserhd of a defrecord with a complex type as a field? I cant find one anywhere


Q: So, for like the fourth time recently, I've wanted something like defmulti/defmethod, except with multiple methods invoked for one multi invocation. I find it strange I've not heard of anyone doing this. Are there things?


@lwhorton Here's a thing from rewrite-clj. "children" is a collection of other nodes.


muchas gracias


@eraserhd sounds sort of like observer pattern? I assume those methods are causing side-effects


In this case, the results are combined with merge.


In a previous case, I wanted to register transducers which could process things in any order.


Can't remember the time before that.


mmmmm, I think the "deciding what to do with the results" bit fights against there being a general solution for that


I don't mind writing the dispatch/combining code, but how to write the registration?


Right now I kind of cheat and use a defmulti and manually call methods with (methods ...).


Which works, and I don't have to worry about implementation concerns about namespaces and loading, but it's kind of awkward to throw away the dispatch key and all.


write a macro that registers the function somewhere?


I'm wondering about, for example, atoms or volatiles, or using a defrecord with fields, and what kind of things we have to worry about wrt concurrency at namespace load.


(def listeners {})

(defmacro defn-listener [name key args & body]
   `(let [fn (defn ~name ~args ~@body)]
      (alter-var-root #'listeners #(...))))


something like that?


yes. Is that a good practice, just using alter-var-root?


if you want to build this all up at compile time, and dispense with some boilerplate I think it seems reasonable. but I'm not going to make any claims to it being good practice ¯\(ツ)


you could also use a ref or an atom


(fn [x] (if (vector? x) x (apply list x))) is there a builtin for this? "if a vector, in O(1) return itself; if a list, in O(n) create a vector"


@hwk Not sure how it behaves under the hood but might this work?


it has to be a vector, but then not satisfy some protocol


@roelofw: there's a mini address book example in the repo you can look at (FYI I'm on vacation thru Sunday so I may not be around to answer questions much)


Is there a more idiomatic way to implement this (sorta-cond) ? (defn pick-first [x lst] (loop [lst lst] (when (not-empty lst) (let [[k v] (first lst)] (if (k x) (v x) (recur (rest lst)))))))