Fork me on GitHub
#clojure
<
2016-09-11
>
didibus01:09:49

So what exactly are "collections". I often see fn docs mentions, take a collection, but I'm not sure which type it refers too. Does it mean clojure.lang.IEditableCollection ?

didibus01:09:41

or is it IPersistentCollection?

didibus01:09:07

OR even broader, the java.lang.Collection?

Alex Miller (Clojure team)01:09:34

I would usually interpret that to mean IPersistentCollection

didibus01:09:22

Cool, thanks

herbm06:09:07

(noobie so confirm anything I write): I think alexmiller is correct -- a collection is anything that implements IPsersistentCollection. Another way would be to say it (coll? coll) returns true. This includes (at least) vector, list, map, set, and records (last surprised me.)

fellshard07:09:19

Deeper shower thoughts: What if - instead of a simple eval bot - an nrepl bot could be created that permits communal visibility and access to a running repl on a given Slack channel?

Madara Uchiha11:09:59

What's the difference between a dynamic binding and just using def with let to create scopes?

Alex Miller (Clojure team)12:09:26

@herbm right - the tricky one is whether seqs are included

amacdougall20:09:42

So I'm rendering a maze of interconnected rooms in SVG. The basic rectangles are trivial; you just write out some Hiccup like [:rect {:x 0 :y 0 :width 10 :height 10}]. And figuring out anchor points is trivial as well; it's not hard to calculate that the northeast corner of that rectangle is [10 0]. I've captured a bunch of calculations about the multipliers involved by calling it a "render environment", a map with keys like :margin and :cell-h-spacing and :cell-width. With those values, I can calculate rects for all the cells:

(into [:svg {...base attrs...}] (map (partial render-cell render-environment) all-cells))

amacdougall20:09:32

But the problem comes when I start drawing the lines between them. Now I need to capture context while rendering. If I have already drawn a line between the cell at [0 0] and its eastern neighbor, I don't need to draw a reciprocal line when I get to that cell.

amacdougall20:09:57

I was thinking of using reduce to keep track of a set of all drawn lines. Thanks to how Clojure handles values, two [:line {:x1 0, :y1 0, :x2 10, :y2 10}] vectors are equal. But reduce gets cumbersome if I want to build up the result collection and accumulate some other value.

amacdougall20:09:21

I'd be doing something like (reduce (partial render-cell render-environment) {:cells [], :lines #{}} all-cells), where render-cell now has responsibility for accepting and returning the {cells, lines} map.

deiga20:09:27

So I’m trying to compile clojure master branch and I get this weird compile error java.lang.NoClassDefFoundError: clojure/spec$map_spec_impl can anyone help me out? 🙂

amacdougall20:09:10

@deiga, if nobody answers here, you might also ask in the #clojure-spec room, where @alexmiller is holding court on spec issues.

Alex Miller (Clojure team)20:09:28

mvn clean compile should usually be sufficient

deiga20:09:02

Hmm, now it works. Guess I had some broken artifact somewher

deiga20:09:08

thanks 🙂

Alex Miller (Clojure team)20:09:22

if you didn’t clean, sometimes that can cause problems

quoll20:09:47

@amacdougall on using reduce… I’m a fan, but I agree that there is a tipping point when you’re trying to accumulate more than one kind of data. Eventually, I find that my code gets clearer when I rewrite as a loop/`recur`. But I don’t have a clear rule about when to make that switch

amacdougall21:09:04

That's a good point. I think I can get away without it, though. I've defined render-cell so that it simply returns a Hiccup SVG like:

[:g
 [:rect ...]
 [:line ...]
 [:line ...]]
And then, during the main reducer that iterates over all cells, we just add all lines in the output to our list of existing lines. render-cell accepts that list as one of its arguments, and omits any line in that set. 👍

stvnmllr221:09:41

If this is too stupid to answer, feel free to ignore. But if i had a datastructure I wanted to save to disk for later. I could use transit right?

gfredericks21:09:03

I don't know if they've lifted that "don't persist transit until we nail down the spec" warning yet

stvnmllr221:09:58

good point. Thanks for the answer. I can always convert formats later. Very small proj for now. JSON would work too, just thought more native would be nice

gfredericks21:09:49

edn is probably a bit easier

Alex Miller (Clojure team)21:09:27

we haven’t (re transit) but there was some chatter recently about whether that should be done

stvnmllr221:09:59

Yeah, I tried EDN a while back and it didnt' work out, but was probably my ignorance. Will consider that again. thanks all for giving me a direction.

gfredericks21:09:49

I can't imagine it's more difficult than transit

yonatanel21:09:02

Is there an elegant way to print threading macro intermediate results?

gfredericks21:09:14

i.e., (-> a f1 f2 (doto prn) f3 f4)

didibus21:09:26

How does Transit differ itself form EDN? Is a binary format, compressed, more expressive?

fellshard22:09:53

If you wanted to print every intermediate, you could create a macro that interleaves the (doto prn) expression between the list of expressions... Gonna try that as an exercise

Alex Miller (Clojure team)22:09:00

@didibus Transit has both JSON (text) and MsgPack (bin) serializations

fellshard22:09:05

First macro 😄

Alex Miller (Clojure team)22:09:06

if you are going to the browser, the JSON parser is highly optimized. because it employs optimizations like key caching, it can surprisingly be faster than conveying the same information over just JSON.

fellshard22:09:09

(defmacro prn->
 [x & forms]
 `(-> ~x
   ~@(interleave forms (repeat '(doto prn)))))

Alex Miller (Clojure team)22:09:49

there are some libs out there that contain printing variants of the thread macros btw if you’re interested in using or comparing

fellshard22:09:23

Would be good to see how more well-considered versions pan out, aye. 🙂

Alex Miller (Clojure team)22:09:56

sorry I can’t remember what those libs are atm :)

fellshard22:09:02

I'll dig around

didibus22:09:21

So Transit is a competitor to something like Google's protocol-buffer

didibus22:09:28

or Amazon ION??

didibus22:09:54

I guess I'm finding my answers from the comments on the cognitech Transit blog

didibus22:09:14

Though it does feel like Amazon ION fills an exact use case

didibus22:09:33

I'm not sure I see where Transit really fits in with clojure. Is it planned to have it be a first class citizen? It really feels to me more like a library side project.

Alex Miller (Clojure team)22:09:07

Transit differs from protobuff in that you don’t need a predefined schema - it is self-describing as it comes over the wire

Alex Miller (Clojure team)22:09:28

I haven’t looked at Ion

didibus22:09:16

Ion is self-describing. But its fair enough, Transit was announced before the reveal of Ion

Alex Miller (Clojure team)22:09:40

I find it funny that Ion does extensibility via s-exprs

Alex Miller (Clojure team)22:09:35

I think Transit’s extensibility story is better based on a quick skim :)

didibus22:09:01

I'll be keeping my eyes open on both 😛

Alex Miller (Clojure team)22:09:27

Transit lets you build new tagged types based on existing types. readers that don’t have a knowledge of the tagged type can still read it and understand it’s parts (and send it along) even if they don’t have a known reader for the type.

machty23:09:54

man, adhoc hierarchies in conjunction with isa?-based multimethod dispatch is so cool