Fork me on GitHub
#clojure
<
2016-07-26
>
michaeldrogalis00:07:34

Can anyone think of a clean way to SHA-256 a Clojure data structure, bearing in mind that when serialized, alternate key orderings in maps or sets would produce different SHAs for equal values.

michaeldrogalis00:07:59

Nevermind, it looks like Clojure's hash is already capable of taking care of reordering, even in nested structures. Pretty rad, Clojure. Pretty rad.

bcbradley01:07:08

after thinking about my problem for a while i came up with a solution:

bcbradley01:07:10

(defn transduce-no-init [transducer reducer coll] (transduce transducer reducer (first (transduce transducer conj (list (first coll)))) (rest coll)))

mpenet07:07:06

@michaeldrogalis: I think you might get different hash values depending on what jvm version you run or even across different runs on the same jvm. Might be relevant/important to your usage.

borkdude14:07:01

I'm writing a blog post and want to understand a detail I'm not sure of

borkdude14:07:58

From Scala I want a launch a socket repl and I have this in build.sbt:

fork := true
javaOptions := Seq("-Dclojure.server.repl={:port 4555 :accept clojure.core.server/repl :server-daemon false}")

borkdude14:07:17

in some source file I have imported Clojure's Java api

borkdude14:07:32

and I have some 'dummy' line that causes Clojure to load

borkdude14:07:41

val require = cvar("clojure.core","require") is enough

borkdude14:07:07

but I can't really explain that part. When I remove the line, nothing happens, because an unused import doesn't trigger Clojure to load?

michaeldrogalis14:07:55

@mpenet: That would be relevant, yes. Thanks for the heads up. I think I'm going to need to rethink it.

mokr15:07:30

Need some CSV parsing advice. The lines I have use quotes around string fields, but leaves integers without. Hence types are encoded in the source. When I parse with clojure.data.csv, all fields ends up as strings, and I loose the type information. Any advice appreciated. Line to illustrate input: “8.5”,”http://your.domain.com”,42,,,”foo”,””,””,”20160725”,”a=b,c=d”

mpenet15:07:21

@michaeldrogalis: it s an interesting problem actually. Maybe you could serialize (nippy?) the ds and then compute a checksum of the byte array. It's probably not very efficient tho. Also nippy will not consider equal some types you might like to be (array-map vs hashmap etc)

michaeldrogalis15:07:32

Yeah, will probably need to just get it to a best effort state. @mpenet Can't imagine most people have this problem 🙂

mpenet15:07:38

A lot of people use hashcodes blindly and live with the possibility of breakage it seems

mpenet15:07:21

Yeah, scary stuff indeed

michaeldrogalis15:07:37

My end goal is content-addressable EDN. Seems like avoiding hashCode is in my best interest, then.

mpenet15:07:10

@ilukinov: technically it's a valid empty coll of ::custom

mpenet15:07:32

I guess you can enforce the presence of at least one element if you need/want to

Alex Miller (Clojure team)15:07:47

@borkdude: just loading the Clojure class should be enough to get the runtime going I think. Class.forName(“clojure.java.api.Clojure”)

Alex Miller (Clojure team)15:07:03

or whatever the equivalent is in Scala

mpenet15:07:04

@ilukinov: (coll-of ... :min-count 1)

Alex Miller (Clojure team)15:07:05

and you are correct that imports do not trigger load in Java - that just helps Java understand names in the context of the file

ilukinov15:07:32

@mpenet: this is terrible, thanks

dg17:07:06

Man I really like spec. Defining a recursive DSL for executing tasks in parallel or sequentially with resource locking... 13 LOC

mpenet17:07:13

Playing with fuzzing for ring compliant client and servers here using spec. Kind of fun

martinklepsch18:07:49

what is the equivalent of (satisfies? IWatchable an-atomlike) in Clojure?

pesterhazy18:07:43

@martinklepsch: (instance? clojure.lang.IRef (atom 1)) ?

ska18:07:24

Hm, I guess I'll take the missing reactions to my question as a disgusted silence while everyone looks away and pretends they didn't see it. 😉

pesterhazy18:07:45

@ska, I saw your snippet, but what's the question ?

ska18:07:15

No worries, @pesterhazy ; I don't like that idea myself. It's about having an atom as a value in a map which gets passed around a lot and then updating that atom somewhen somewhere. I'll think of something better.

pesterhazy18:07:32

I don't think there's anything wrong with that idea per se, but it depends on how you want to use it.

ccann18:07:14

anyone know how to specify that map keys are mutually exclusive with schema?

dg19:07:51

@ska I would consider storing the mutable part separately

michaeldrogalis21:07:48

@danielcompton: Someone suggested that earlier. That's what I ended up using 🙂