This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-09-11
Channels
- # bangalore-clj (1)
- # beginners (24)
- # boot (134)
- # boulder-clojurians (2)
- # cider (3)
- # cljs-dev (2)
- # cljsjs (44)
- # clojars (9)
- # clojure (60)
- # clojure-greece (2)
- # clojure-quebec (1)
- # clojure-russia (44)
- # clojure-spec (15)
- # clojure-uk (1)
- # clojurescript (37)
- # core-matrix (1)
- # datomic (7)
- # emacs (1)
- # hoplon (154)
- # liberator (3)
- # mount (2)
- # om (20)
- # onyx (2)
- # pedestal (3)
- # planck (12)
- # re-frame (26)
- # reagent (32)
- # uncomplicate (4)
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 ?
I would usually interpret that to mean IPersistentCollection
(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.)
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?
What's the difference between a dynamic binding and just using def
with let
to create scopes?
@herbm right - the tricky one is whether seqs are included
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))
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.
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.
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.
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? 🙂
@deiga, if nobody answers here, you might also ask in the #clojure-spec room, where @alexmiller is holding court on spec issues.
@deiga how are you compiling?
mvn clean compile
should usually be sufficient
if you didn’t clean, sometimes that can cause problems
@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
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. 👍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?
I don't know if they've lifted that "don't persist transit until we nail down the spec" warning yet
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
edn is probably a bit easier
we haven’t (re transit) but there was some chatter recently about whether that should be done
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.
I can't imagine it's more difficult than transit
(doto prn)
i.e., (-> a f1 f2 (doto prn) f3 f4)
How does Transit differ itself form EDN? Is a binary format, compressed, more expressive?
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
@didibus Transit has both JSON (text) and MsgPack (bin) serializations
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.
there are some libs out there that contain printing variants of the thread macros btw if you’re interested in using or comparing
sorry I can’t remember what those libs are atm :)
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.
Transit differs from protobuff in that you don’t need a predefined schema - it is self-describing as it comes over the wire
I haven’t looked at Ion
Ion is self-describing. But its fair enough, Transit was announced before the reveal of Ion
yeah, looks similar
I find it funny that Ion does extensibility via s-exprs
I think Transit’s extensibility story is better based on a quick skim :)
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.