Fork me on GitHub

There is some function that does (??? [:a :b :c]) ;; => [[:a :b] [:b :c]]


(partition 2 1 coll) @souenzzo

😍 4

How can I reload a NS in REPL?


I am trying to develop an app which dynamically loads namespaces specifies by a user. If I use REPL and namespace load fails because of a mistake, then rerunning (require '[my-ns :reload :verbose]) doesn't reload the namespace, running the code produces same error over and over again until I restart the REPL.

Jan K10:10:31

@roklenarcic I think it should be (require ['my-ns] :reload :verbose)


@jkr.sw you were right, I was using reload wrong


An idiomatic question: Did you find useful to use records for domain objects in system instead of plain maps? E.g.: When a function receive a user object from an HTTP response it converts the response to User record like (map->User response) instead of passing “just plain response” around.


Plain maps with namespaced keywords much more ideomatic than records, imho.


I think opinions differ here. Many people prefer plain maps though. The Clojure Applied book shows a usage of records. Here's an interesting discussion on this Slack:

* seancorfield @alexmiller On that subject... given the general advice re: maps / records is usually "use maps, and only switch to records if you need extra performance", how does that sit with using namespaced maps -- since those cannot easily be switched to records?
* alexmiller it complicates it :)
* alexmiller I mean if you have maps with namespaced keys, you can switch to records and change specs from :req to :req-un
* seancorfield Fair enough. The spread of namespaced maps does seem to reduce the attraction of using records further.
* alexmiller unfortunately, I agree. I seem to be in the minority, but I like records. :)


not really, I only find it useful if you are using polymorphism somewhere (i.e protocols)


or if you need performance


Any spec-experts know the solution to this problem I posted a while back?

Alex Miller (Clojure team)12:10:02

Why not s/nonconforming? You seem to be excluding the thing that does what you want?


I might be remembering wrong, but s/nonconforming excludes all other kinds of conforming that you might end up wanting as well, right? That's what I was hoping to preserve!


Sorry if my simple example gave the impression that I didn't need to conform the rest either!


i think i’m being silly, but is it possible to invoke clojure -m my-ns.-not-main?


i figure if java requires always requires a main then we always have to start a clojure program via -main?


I think Alex has considered an arbitrary fn entry point before. A JIRA ticket might even exist


it would make it a little easier to keep alike fns in the same namespace. for example i have build-tools which has a handful of useful scripts, but if i have to always expose -main it’s a little more annoying to consume from the cli

Alex Miller (Clojure team)15:10:40

you can invoke clojure myscript.clj which has an arbitrary top-level call in it

Alex Miller (Clojure team)15:10:05

$ cat foo.clj
(defn hi [] (println "hi"))

$ clj foo.clj

Alex Miller (Clojure team)15:10:48

or you can combine -i and -e for similar effect

Alex Miller (Clojure team)15:10:02

$ cat foo.clj
(defn hi [] (println "hi"))
$ clj -i foo.clj -e '(hi)'

❤️ 4
🙂 4
Alex Miller (Clojure team)15:10:18

you can have multiple -i’s to load multiple files


any advice for working with WSDL web services from clojure?


I started down that path several years ago. Tried to find a well-maintained Clojure library. Gave up. Forked one and got it running on an up-to-date version of Clojure but I couldn't get it to work satisfactorily. Ended up using Java interop and Java Axis libraries directly. Unpleasant but not as unpleasant as doing it in Java 😐


kinda drowning in SOAP


How do you name your transducer xforms? I am recently using more and more reusable xforms and I started wondering — any naming conventions to mark them as being different from a function?


@jrychter I’m not aware of any convention


@emccue last time i had to do that i used SoapUI to explore the api and to generate some template requests, filled out the requests with some simple mustache-like string templating... then to parse the responses - cheesy code, but effective


why clojure's assert not use java's assert?


why do you think that it doesn't?


@isaac java's assert isn't a JVM level construct. It's a Java language construct. There's very little way for Clojure to "use it".


Java's assert simply checks a condition and throws an AssertionError if the condition fails. Clojure does the same thing.


what kafka libs are people using these days? most of the libs seem a bit outdated


the official Java driver + interop is my recommendation


my company is open sourcing our kafka lib soon, it uses spec with avro extensively, one of my coworkers will be presenting it at clojure/conj


but yeah, interop is good for a start


exactly the guy, he was the tech lead on my previous team, now he's on the architecture team


i looked for kafka on the speakers list. i don't know him


(our project was wildly successful when it went live, and was 100% a "consume from a bunch of kafka, and publish a bunch of kafka" thing)

👍 4

Recently had a need to write and read clojure data structures to/from file


however - doing a read-string to convert string back to clojure data structure doesn't work well on java arrays -


I get a "RuntimeException No reader function for tag object"


I'd recommend using the transit library - it's easy to extend to any data type


arrays are mutable, so they are intentionally not printed readably


ok I see - I will try that - thanks


With immutable data, writing it out than reading it back is literally the same as using the original object. With something mutable, it's not.


hmm ... I guess that makes sense. With mutable data structure - it's printing more the meta data - than the data


transit is way faster than EDN, but last I checked Transit was also marked as "not done" and "may change in the future, don't use this for at-rest data".


That being said, the format hasn't changed in the past 4 years


also, compared to other relatively fast alternatives, it supports all the core clojure data types and accepts first class reader and writer config at call site rather than as a global config


agreed. If you need more performance you can also use fressian which is what Datomic uses to store data. It's clojure-only, but very stable, very fast, and it's a binary format, so it's quite compact:


fressian + json encoding = transit (for the most part)


@tbaldridge What the performance diff between fastxlm jackson and transit?


Thank you for the pointers - I've used transit quite often - particularly on clojurescript side - will also check out fressian


Well transit is the only one with caching/dedupping so in many cases it will be the fastest. I have yet to see XML ever be faster than JSON


if you have a keyword reported over and over, transit will replace the keyword with ^1, ^2 etc.


That means a savings in space, and also a performance savings on both ends as the same value can be plugged in instead of reading/interning the keyword every time.

👍 4

definitely - space saving would be welcome 🙂


Hi Clojurians. Is there a way to take a Clojure collection like

[{:k1 "v1", :k2 "v2"} {:k1 "v3", :k2 "v4"}]
and return it as the JSON equivalent
[{"k1" : "v1", "k2" : "v2"}, {"k1" : "v3", "k2" : "v4"}]
I used Cheshire and it's generate-string function, but it results in a single string with escaped quotes, e.g.
and I tried parse-string on that, but it results in something like this without the colons:
[{"k1" "v1", "k2" "v2"}, {"k1" "v3", "k2" "v4"}]


json is a serialization format


"[{\"k1\":\"v1\",\"k2\":\"v2\"},{\"k1\":\"v3\",\"k2\":\"v4\"}]" is what it looks like printed via prn


So if I wrote that to a file from Clojure, would it have the non-escaped version?


it depends how you wrote it


I'm basically trying to randomly generate some data which will be used within an api from a json formatted feed (i.e. from a json file)


if you used pr anywhere it will have the escaped parts because pr outputs things that can be read back in, so inside strings " needs to be escaped, etc


if you do something like (println (generate-string {:a 1})) you will get json without the escaping


Perfect, that did the trick! Thank you @hiredman 🙂