Fork me on GitHub
Brandon Olivier00:03:45

It was a Jackson issue (I think)

Brandon Olivier00:03:10

I installed version 2.10.3 of Jackson and now it's functioning correctly

Brandon Olivier00:03:22

I'm not sure I quite understand what went wrong

Brandon Olivier00:03:31

Why didn't leiningen pick up that I needed it?


tl:dr jackson is terrible


it uses your recursive deps, the version of jackson someting else used was not compatible with the versin amazonica needed


by adding a version explicitly, you forced it to use the version amazonica could use


luckily you didn't also break some other lib in the process (that can happen sometimes)

Brandon Olivier00:03:03

Does that mean that somewhere a project had an implicit dependency on jackson, or that lein chose a different version to use?


that's why I suggested running lein deps :tree - that exposes the recursive dep path (the short version is lein goes depth first and registers versions in order of your dep vector)


it also warns you if different libs wanted different versions of the same lib, usually this is innocuous because libs maintain some compatibility, but jackson really doesn't do that

Brandon Olivier00:03:05

interesting. Thanks for the help 🙂


@noisesmith I'll agree that Jackson is terrible (from a version conflict p.o.v.) but it's so widely used it's hard to get away from. Are there non-Jackson JSON options that behave better?


(asking for a friend, honest!)



it's not perfect, but will never get you into dependency hell


I recall that once upon a time, in the distant early years, many of us changed from data.json to cheshire because data.json had a release that renamed a few functions. But it was long enough ago I could be remembering wrong.


I just went and looked at metosin/jsonista hoping it wasn't based on Jackson. It is.


(we switched from data.json to Cheshire because the former failed to correctly format some things we had -- but Cheshire worked flawlessly... of course, I should have reported a bug against data.json which I don't think I did, because I needed a working JSON converter "immediately" to resolve a problem at work)


Cheshire depends on Jackson also. I guess it uses it in a different more performant way, but that wouldn't prevent dependency problems.


Right, and lots of things use Cheshire under the hood so it's very hard to avoid Jackson 😞


clj-http, for example, if you use any of its built-in JSON stuff.


Yes, I'm using etaoin and it also uses Cheshire. At work we've also had lots of problems with Jackson breakage.


Ya, I was surprised that no Clojure wrapper for Gson existed. Maybe the Gson model doesn't let you build a Clojure parser, and is too specific to Java. But Gson in Java land is much more dependency friendly.


oooh - that might be a worthwhile evening hack :D


looking at the API, seems very sensible so far (should be easy to use directly...)


regarding the Gson discussion the other day: as far as I'm concerned this just works and doesn't require a wrapper lib:

user=> (def gson (Gson.))
user=> (.toJson gson {:a 0 :b 1 :c [1 2 3] :d #{4}})
custom type registry that isn't global:
user=> (def gson-custom (
user=> (.registerTypeAdapter gson-custom clojure.lang.Atom (reify (serialize [this src _type context] ( @src))))
#object[ 0x145414f ""]
user=> (def gson-2 (.create gson-custom))
user=> (.toJson gson (atom 12))
user=> (.toJson gson-2 (atom 12))


What about from Json ?


I didn't actually experiment with that half yet, but it definitely looked straightforward


Another possibly "cool?" option. I wonder if Cheshire could bundle the Jackson libs in a shaded state.


It's like taking the appropriate Jackson libs, renaming the package to something unique, have Cheshire import those renamed packages, and bundle them with Cheshire.


Neither know how easy, or if licenses would allow

Chester ONeill18:03:21

Can cider just load functions from a local file? I've set up emacs and I can start cider-jack-in but it gives me an error that im not using a project. I just want to have the repl load in my functions and be able to edit them and run. any ideas?


cider-scratch can be used if you dont have a project. However, as you are creating a file, then it will simplify things greatly if you create a Clojure project. Leiningen is a build tool that has been around for a long time, so lots of people use it to create a project. Clojure CLI and tools deps is the approach many people are taking for new projects.


As people have mentioned, the BraveClojure Emacs setup setup is about a dozen major releases out of date and significant changes have been made to CIDER.


For Emacs & Clojure, Prelude, Doom and Spacemacs seem to be the most popular community configurations. Prelude provides the essentials, Doom provides a bit more opinionated features and Spacemacs is a full batteries included experience. I use Spacemacs and am writing this guide on Clojure development with Spacemacs/Emacs


@me1159 it wants to start an nrepl from a specific project, you can set emacs' current directory before running jack-in, or start emacs from that dir, or use cider-connect and point it to a port for a repl you already started

Chester ONeill18:03:25

You mightve mentioned the wrong person 😃 ha

Chester ONeill18:03:13

how would I set emacs current dir after its started?

Chester ONeill18:03:20

I guess I can google that


I think default-directory is actually the thing you want though, q's assumptions notwithstanding


@me1159 sesman-link-* commands are also useful if you already have a repl and just want to connect it to a file in a different dir

Chester ONeill18:03:34

so i tried using the cider-connect-clj to connect it to the same instance that cider-jack-in-clj started but im not really clear how to fun the function I have in my file

Chester ONeill18:03:34

maybe the way I want to do this is just wrong. I basically just want to have a scratch pad of functions I can just rapidly iterate on and run in a repl without needing lein and stuff.

Chester ONeill18:03:56

Ive just been copying things out of a file and into the repl and running them but thats tedious


if your file didn't define a namespace form, the function you defined should end up in the repl's default ns, or user if there is none


you can use (apropos "function-name") also


user=> (apropos "merge")
(clojure.core/merge clojure.core/merge-with clojure.spec.alpha/merge clojure.spec.alpha/merge-spec-impl)


@me1159 clojure namespaces everything, so even for "scratch" code, it's less friction to just put (ns scratch) at the top of the file


or whatever you want to call your default / dummy / wip ns

Chester ONeill18:03:22

so my function is just

(defn foo
  (println "foo)) 

Chester ONeill18:03:27

ill try namespacing it


if you do (apropos "foo") it will show you where it ended up

Chester ONeill19:03:57

so I get this

user> (apropos "foo")


i made a directory in /tmp/blah, made a file called foo.clj, cider-jack-in and everything works for me


can you list the steps you are doing?

Chester ONeill19:03:53

does it also matter I loaded up the clojure for the brave and true defaults for emacs. Im also using the gui emacs not the emacs that comes preloaded on mac


the above is gui emacs. can you link me to the clojure for the brave and true setup you're using?


that's an old CIDER. can i recommend using a well done emacs startup called prelude? It's by the maintainer of CIDER and is tastefully done:

Chester ONeill19:03:39

im totally cool with that


awesome. let meknow if you run into any problems

Chester ONeill19:03:28

thanks. yea ill try that and see if it that works. I knew there was no way it could be this difficult

Chester ONeill19:03:13

btw just curious where did you find the cider version that project was using? I know he takes PR's to keep that stuff updated

Chester ONeill19:03:42

don't kno why but I installed prelude and theres no cider options available when M-x

Chester ONeill19:03:19

sry to spam you. I got cider installed. stil the same issue. cider just doens't bring in the file. im going to try something else.


how are you trying to "bring in the file"?

Chester ONeill20:03:26

im just simply starting cider-jack-in from the buffer where the file is

Chester ONeill20:03:04

I literally setup the same structure as you

Chester ONeill20:03:24

foo.clj , ns foo, defn foo that adds a number


ok. so you need to eval the file


clojure works on what has been loaded. it isn't loaded without some action

Chester ONeill20:03:22

ok. is that (load-file) then?



Chester ONeill20:03:51

M-x that in the cider buffer?

Chester ONeill20:03:21

sorry im like drinking from the clojure/emacs/cider firehouse right now trying to set up an envrionment


but perhaps reading some documentation wuold be helpful?

Chester ONeill20:03:34

god damnit =( PEBKAC

Chester ONeill20:03:47

thank you for your help. going too fast here.

Chester ONeill20:03:13

This is making more sense now. The whole repl idea and live coding is insane but this is neat. thanks again so much


that means the current clojure process didn't get a foo defined anywhere


on my API i’m checking if some parameters are present

(or (empty? customer-uuid) (empty? debtor-uuid))
(error-response "Customer or Debtor UUID is missing!")
the error-response is a bit meh.. how would you get the parameter that is missing (or both), and add that to the message so that is reads like "customer_uuid` is missing, but expected UUID"`


I'd probably use cond and have each error condition tested separately (so they each can have a separate error response), then :else (happy-path) at the end of the checks.


@U04V70XH6 so you test 3 conditions? 1 - neither are present 2 - customer is not present 3 - debtor is not present


(cond (empty? customer-uuid) (error-response "`customer-uuid` is missing")
      (empty? debtor-uuid) (error-response "`debtor-uuid` is missing")
      :else (happy-path))
depending on exactly what error messages I wanted from which conditions.

Brandon Olivier19:03:42

Is there an idiomatic way to write to files in directories that may not exist?


(doto f (-> .getParentFile .mkdirs))

👍 4

why doto though? (-> f .getParentFile .mkdirs) seems to work just fine


you need either doto or -> , not both

Alex Miller (Clojure team)20:03:55

if you want to avoid interop


doto on the assumption you have an expression that contains f


you can drop in the doto expression in place of f, without the doto you cannot


Wondering about best practice when it comes to protocols. In Java I'd declare an Interface, let's say MessagingService, in its own self-contained file. I'd then create two other files, RabbitMQService and DummyService, and in each implement the Interface. In Clojure, do most declare these things all in the same file?


it's really up to you - one place for protocols vs. various implementations, vs all in one place - it's more a question of your app's needs, but it is usually simpler to put the implementations with the protocol if they are created to be mutual alternatives rather than something open ended for user extension

👍 4

On contrary, I'd recommend putting the protocol in a separate namespace, not only for code organization but to avoid issues with code reloading in the REPL


@U06GS6P1N it's the opposite - if every extension of the protocol is in the same ns as the protocol, you don't end up with the protocol and extensions going out of sync


the protocol and instances implementing it can go out of sync just as easily with both approaches


actually, I guess if you never reload the protocol ns, that can help with values going out of sync with the protocols they implement


I have a 2-d vector with values in each position, and I'd like to set values inside a certain range of x and y coordinates. Is there an idiomatic way to do this functionally? I know how I'd do it imperatively, but I can't figure out a simple way to do this functionally.


Something like a cumulative for loop?


clojure for is a list comprehension, not a loop - it's useful for generating lists but not transforming inputs per se


@ordoflammae I would use a reduce with (range i j) as a collection input providing all the indexes


something like (reduce (fn [v idx] (update v idx f)) my-vec (range i j))


where if takes current value at index idx and returns the replacement


(you can change the update call if f should get different input, of course)


Ah. Thanks @noisesmith for the help.


That makes so much more sense.


(ins)user=> (def i 2)
(ins)user=> (def j 5)
(ins)user=> (reduce (fn [v idx] (update v idx (fn [old] (+ old idx)))) [1 1 1 1 1 1 1 1] (range i j))
[1 1 3 4 5 1 1 1]


for indexes i through j-1 (2,4) it updates value at index by summing with its index


regarding the Gson discussion the other day: as far as I'm concerned this just works and doesn't require a wrapper lib:

user=> (def gson (Gson.))
user=> (.toJson gson {:a 0 :b 1 :c [1 2 3] :d #{4}})
custom type registry that isn't global:
user=> (def gson-custom (
user=> (.registerTypeAdapter gson-custom clojure.lang.Atom (reify (serialize [this src _type context] ( @src))))
#object[ 0x145414f ""]
user=> (def gson-2 (.create gson-custom))
user=> (.toJson gson (atom 12))
user=> (.toJson gson-2 (atom 12))