Fork me on GitHub
#clojure
<
2018-10-16
>
souenzzo02:10:17

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

ghadi02:10:46

(partition 2 1 coll) @souenzzo

😍 4
roklenarcic10:10:24

How can I reload a NS in REPL?

roklenarcic10:10:01

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)

roklenarcic11:10:48

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

lukas.rychtecky11:10:53

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.

delaguardo12:10:08

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

jumar08:10:27

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. :)

schmee11:10:40

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

schmee11:10:00

or if you need performance

oddsor12:10:33

Any spec-experts know the solution to this problem I posted a while back? https://clojurians.slack.com/archives/C03S1KBA2/p1539171271000100

Alex Miller (Clojure team)12:10:02

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

oddsor12:10:06

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!

oddsor12:10:13

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

lwhorton14:10:44

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

lwhorton14:10:18

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

ghadi14:10:19

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

lwhorton15:10:05

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"))

(hi)
$ clj foo.clj
hi

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)'
hi

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

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

emccue15:10:23

any advice for working with WSDL web services from clojure?

seancorfield16:10:32

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 😐

emccue15:10:57

kinda drowning in SOAP

jrychter16:10:08

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?

cgrand16:10:26

@jrychter I’m not aware of any convention

mccraigmccraig16:10:28

@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 clojure.data.xml to parse the responses - cheesy code, but effective

isaac16:10:23

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

ghadi16:10:30

why do you think that it doesn't?

tbaldridge16:10:41

@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".

tbaldridge16:10:08

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

mping17:10:37

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

schmee17:10:33

the official Java driver + interop is my recommendation

noisesmith17:10:46

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

noisesmith17:10:02

but yeah, interop is good for a start

noisesmith17:10:52

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

dpsutton17:10:09

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

noisesmith17:10:27

(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
bajrachar17:10:46

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

bajrachar17:10:51

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

bajrachar17:10:16

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

noisesmith17:10:22

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

noisesmith17:10:37

arrays are mutable, so they are intentionally not printed readably

bajrachar17:10:01

ok I see - I will try that - thanks

noisesmith17:10:24

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.

bajrachar17:10:04

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

tbaldridge17:10:56

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".

tbaldridge17:10:11

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

noisesmith17:10:48

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

tbaldridge17:10:55

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: https://github.com/clojure/data.fressian

tbaldridge17:10:14

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

isaac17:10:33

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

bajrachar17:10:00

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

tbaldridge17:10:16

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

tbaldridge17:10:00

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

tbaldridge17:10:34

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
bajrachar17:10:28

definitely - space saving would be welcome 🙂

yogidevbear19:10:00

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.
"[{\"k1\":\"v1\",\"k2\":\"v2\"},{\"k1\":\"v3\",\"k2\":\"v4\"}]"
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"}]

hiredman19:10:24

json is a serialization format

hiredman19:10:49

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

yogidevbear19:10:26

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

hiredman19:10:01

it depends how you wrote it

yogidevbear19:10:20

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)

hiredman19:10:01

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

hiredman19:10:52

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

yogidevbear19:10:09

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