This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-01-27
Channels
- # alda (21)
- # announcements (7)
- # beginners (70)
- # boot (95)
- # braid-chat (28)
- # bristol-clojurians (2)
- # cider (22)
- # clara (4)
- # cljsjs (13)
- # cljsrn (40)
- # clojure (93)
- # clojure-argentina (1)
- # clojure-art (1)
- # clojure-miami (3)
- # clojure-norway (1)
- # clojure-portugal (2)
- # clojure-russia (39)
- # clojure-sg (3)
- # clojurescript (25)
- # clojurian-chat-app (4)
- # community-development (5)
- # conf-proposals (20)
- # cursive (48)
- # datomic (39)
- # devcards (5)
- # dirac (4)
- # editors (2)
- # events (11)
- # funcool (65)
- # hoplon (95)
- # jobs (12)
- # ldnclj (4)
- # lein-figwheel (2)
- # leiningen (1)
- # om (311)
- # onyx (20)
- # philosophy (4)
- # proton (41)
- # re-frame (83)
- # reagent (49)
- # ring-swagger (3)
- # spacemacs (8)
- # yada (5)
@mikeb: I haven't actually tried hooking it up yet, but Foundation's dynamic queries look like they'll do exactly what I want, while preserving the advantages of SQL templates. Good stuff! I'll see if I can't implement it next time I sit down to hack on this project.
@jaen usually you look to multimethods when you're doing value-based dispatch. Protocols are quite a fair bit faster, so they are preferred where applicable
protocols are about 5x faster for type-based dispatch (but that's all they do)
I have a repo that benchmarks some value and type-based dispatch options at https://github.com/puredanger/poly-timing/blob/master/src/poly_timing/core.clj - just clone and "lein run"
Yeah, I know they are faster. Hard for them not to be, since they compile down to Java's virtual dispatch and that's been optimised for last 20 years (didn't see that benchmark before though, thanks for the link), but I just feel kinda weird that I have to go to nominal, OO-like style in a language where it's usually not like that. Was mostly wondering what advantages protocols have over the alternatives (philosophically maybe). If it's just the performance I don't feel that compelled to start using them over multimethods (though I imagine using extend-type
is not as unreadable as extending in-line in the defrecord
), unless I actually have performance problems.
@jaen @alexmiller quite often I use ordinary maps to lookup functions, 14x slower than protocols but quick and easy to write
sorry more like 2x as slow
actually, using criterium to benchmark, there's not much in it
anyway, personnally I find protocols kinda nice, reminds more of haskell typeclasses than "OO-like" stuff
what would be nice is an alternative representation to protocols where you can write multiple type-based implementations of a function, with the same semantics as arity-based function defs
I suppose you could do something like this with extend-type
:
(extend-type MyType Countable
(cnt [c] ...)
(extend-type MyType Foo
(bar [x y] ...)
(baz ([x] ...) ([x y & zs] ...)))
I wish more was written about protocols as I really like them but it took a while to understand and appreciate them.
When used well they really are effective: core.matrix does a good job of this, as does some of http://thi.ng, like http://thi.ng color
I have some nitpicky things I don't like about core.matrix, such as inconsistent and too long lines in docstrings (would be nice if they were all 80chars) but overall it is very well organized and docstringed and such.
jaen: correct me if I am wrong, but also when you "inline" the functions in the record definition it actually compiles to java methods to that record, unlike with extend-type
@meow: we wrote a lot about protocols in Clojure Applied
@mpenet that's true although due to the site cache that protocols make there's not as much perf difference as you'd think
never bothered profiling this kind of stuff, if you need to go that far one would probably choose something else than clojure in the first place 😄
What fun would that be?
@alexmiller: You know I have nothing but the utmost respect for you. I just think things like protocols need to be written about outside of books that not everyone is able or willing to pay for.
I can recommend paying for Clojure Applied--truly a great general overview on how to build a Clojure app
@meow: if you have specific topics, would love to have a clojure-site issue for things to add
That said, I agree advanced features need better docs
I just purchased http://howtoclojure.com on a whim, and plan to write up some tutorials and examples when I get a chance
It took a couple years to write Clojure Applied - takes a lot of time to write stuff
@mpenet: that would would be "less nice but more performant" to me; I kind of don't like how defrecord
s with many methods look. Feels like - ugh - Java.
But good point, I didn't know extend-type
compiles differently to extending in the body of defrecord
.
I contributed to a Python book once so I know they take a ton of time and you only make peanuts for doing so.
Does anyone here have any recommendations for particularly fast HTML parsers in clj?
chiming in on the previous discussion re: protocols. multimethods and protocols are related but not interchangeable
is there anything considered current best practice regarding namespace naming shemes? it seems like some projects use a reverse domain name scheme like (defproject com.jjttjj/my-lib ...) then (ns jjttjj.my-lib.core) and others just do (defproject incanter...) (ns incanter.main...) ... is either one considered strictly better these days?
also do i use the "com." prefix in the directory structure/namespace name? some things seem to use that in the project name but nowhere else
jjttjj: you should have a prefix so that it is unambiguous, wouldn't conflict with another project
as for the other side of the name -- I like to keep it semantically accurate. something.core
is just the leiningen default
thanks. i feel like i use this slack to ask the dumbest kind of irrelevant style questions but this one doesn't really seem to be talked about anywhere and i'm gearing up to release my first open source thing and i figure i might as well ask around and get these things right on the first release
What's the most concise way to make a vector [a b]
or [a]
or [b]
or []
out of a
and b
, where each value should be in the vector only if it is truthy? I have (vec (concat (when a [a]) (when b [b])))
now, which seems awfully verbose.
This might be the wrong place to ask this question, and I apologize if so. I am wondering if it is possible to issue a single command from the console that starts lein repl
and also executes a couple of commands once the repl starts... similar to ruby's irb -e "puts :started_irb"
(into [] (filter identity [a b]))
?
@mbertheau: careful as nil? will only remove nil, not false
@manderson: Thanks for the heads-up. nil?
is sufficient in my case.
Can someone help me understand why the two statements produce different results?
=> (reduce + (map bigint (seq (byte-array (range 0 400)))))
6072N
=> (reduce + (map bigint (range 0 400)))
79800N
Hi Clojurians, I would like to know the meaning of this symbol: ^ but is not easy to find on google. I saw a code like (fn [^Character x] ...
@sstawecki: it tells the clojure compiler the java type of the thing to the right, so that it doesn't have to perform reflection for java method calls where that type could change what method is called
for your googling : it’s called “type hints"
Thanks @bfabry ! thanks @pguillebert I was reading here https://en.wikipedia.org/wiki/Circumflex 😅