This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-06
Channels
- # adventofcode (24)
- # aleph (1)
- # bangalore-clj (2)
- # beginners (196)
- # boot (148)
- # cider (18)
- # clara (83)
- # cljsrn (24)
- # clojure (210)
- # clojure-brasil (3)
- # clojure-china (1)
- # clojure-italy (11)
- # clojure-korea (8)
- # clojure-russia (82)
- # clojure-spec (115)
- # clojure-uk (130)
- # clojurescript (109)
- # core-async (7)
- # cryogen (1)
- # cursive (22)
- # datascript (11)
- # datomic (6)
- # devcards (2)
- # emacs (1)
- # garden (1)
- # hoplon (2)
- # incanter (1)
- # klipse (4)
- # luminus (4)
- # off-topic (89)
- # om (53)
- # onyx (78)
- # parinfer (9)
- # proton (3)
- # protorepl (20)
- # re-frame (107)
- # reagent (52)
- # rum (30)
- # spacemacs (1)
- # testing (3)
- # untangled (31)
- # vim (43)
- # yada (9)
@shaun-mahood my 2c I found that using the actual namespace + field name did not work for me, even with an alias, so I now use something like :receipt/id
and :order/id
... which might end up in the same map (and a lot of times do)
Other opinions/reports are welcome on this too
Another idea that emerged at the Conj by talking with someone was to have a repo of specs + generators for common domains
@richiardiandrea: that's how I do it for some things within my projects, but I'm not sure of what I should be doing otherwise or how it should look across the whole spectrum - like com.whatever.something
and how that goes from there and all the way through a project, with specs as well. Like of there was a reference to make it all work nicely the whole way from top to bottom.
My experience with the above approach has been smooth, I have been bitten by the "package name in namespaced keyword" problem and never went back to it...but yes, no real reference here, just opinion :D
i do the same thing as you so far in my toy projects, @richiardiandrea
i don’t refer to the file’s ns or the project’s name, just to concepts, like :event/id or :weapon/shots-per-second
my specs look like this: https://github.com/jrheard/voke/blob/master/src/voke/specs.cljs
Yes I think it all comes from how Datomic does it as well
(i’ve never used datomic - one of these days! also to everyone else, i have no idea what i’m doing, don’t read my lines above and think “boy this guy knows what’s up, i’ll just do what he’s doing”)
Ah ah now this makes to me too anyways :)
it’ll be nice once best practices are established and written down - i think right now we’re in a “everyone go ahead and try things out and see what works best” stage
My big problem is that I mainly work on projects where I'm the only developer, so noone else notices when I do things completely backwards.
oh that's a bummer. i'm lucky enough to be in a room of four developers and we are constantly talking about style and correctness
speaking of which, is there a way to stop a reduction and return without reducing the whole collection?
i'm pretty sure there is if i reify an interface, but is there a way to do it with just a standard reduce call?
> speaking of which, is there a way to stop a reduction and return without reducing the whole collection?
some who can tell me what selmer uses as root when placing a image with <img src = "?? "> . I tried /img/image.jpg and img/image.jpg but no image is seen
@bhauman thanks for pointing to advent of code, i was lamenting there was no "perl advent calendar" for clojure this year
Anyone, kinda like code golf. Everyone who can program can brute force all the challenges, it's about how elegant/efficient you want to be.
@poooogles thanks, maybe I take a look at it
Hello, I'm trying to transform a vector of maps to a map of the keys to a set of their values. Something like this:
(foo [{:a 1 :b 2} {:a 1 :b 3}])
;; => {:a #{1} :b #{2 3}}
Because I'm going from a collection of maps to a single map, I'm thinking that reduce
will be the best option for this. Am I looking in the right direction?I'm having a massive argument in a pull request review with someone who wants to store empty strings instead of nil in a map that serves as a cache. They don't want to call "contains?" on the map because of "performance" and would rather check if the string is empty by calling seq on it.
am I being a pedant?
"why worry when you can measure” — Rich Hickey
Unless contains?
is provably slower than (= (get x k) "")
(which I would expect the reverse), I think contains?
is significantly more idiomatic.
Not to mention "the value associated with this key is nil" is better than "the value associate with this key is nil but we store an empty string and check for that instead of nil because of unfounded assumptions about performance"
i would use nil as well, because that’s idiomatic, but to convince your colleague who is basing this on perf; just measure it. test a million seqs on strings and a million contains? and see which is faster, and then see whether the difference actually matters
i suspect you’ve spent more time arguing about it than you’d have saved in cpu cycles 🙂
… unless you’re both on the team that built http://hollow.how/
and wouldn't that make three cases for keys in your cache? It is not present and you get nil. It was at some point present but no longer and it is now "", it is present and has a string value
we have spent far more time arguing about it than any approach could possibly save
@jcromartie we all know a Sheldon 🙂
I just had to unsubscribe and let him get someone else to approve it.
I can't be bothered
is it perhaps easier to swallow this pull request now and put it on the back burner to correct it later?
it's not open source
well, not yet... he's a paid team member
there are plenty of other people who can review
he's obstinate
I already made my case
nah, I'm not the gatekeeper, just one of many possible reviewers
i agree. the developer on the other end of the pull request is arguing a performance argument
but if someone has planted their flag i was wondering if it was easier to just accept
i think performance arguments always have to come with metrics and a problem statement
you have to demonstrate that you are improving performance and improving it at a part where performance is a hindrance
I try to make O(n^3) algos whenever I can so if we need speedups later we can quickly impress the higher-ups
@mpenet excellent point
their performance argument is null and void BTW
I've demonstrated that
they responded by abstracting out the logic that stores "" in two place into a call to a function that takes a value and returns "" if nil
so they've doubled down by adding more code
and a function that takes a value and returns nil if it's ""
with docstrings and everything!
I should tell them they need to add unit tests for these functions 😆
is there a bot that is logging channel conversation and mirroring it somewhere public by any chance?
nvm, found it here: https://clojurians-log.clojureverse.org/
@jcromartie "No problem can be solved from the same level of consciousness that created it.” — Albert Einstein
move on, buddy 🙂
@jcromartie: so, one way to deal with this depending on how engineering works where you're at is to accept and just change it later
of course, I could just open my own PR
So, I have a collection and a series of functions. These functions will filter the data, transform it, filter it again, and then emit it to a core.async channel. Is comp
the way to go on this or is there some way or reason to use transduce
even though I don't really have a reduction step (unless you want to consider removing an item from the collection and emitting it a reduction operation)?
(chan 1 (comp (map ..) (filter ..) (map ..)))
the channel will apply those operations when you put to itokay, thank you
@zentrope https://github.com/luminus-framework/luminus-template/blob/master/resources/leiningen/new/luminus/db/src/sql.db.clj
if you just want a few lines to copy, the (extend-protocol jdbc/IResultSetReadColumn part
Ah, that seems familiar. I could swear there was a gist or something illustrating this.
If you are opening a resource, you should use with-open.
If the reader is passed in from somewhere else, you probably shouldn't close it. It all depends on the context.
Is there something like line-seq but suitable for transducer composition - does that make sense at all?
@borkdude clearly you wouldn't feed a transducer into line-seq, so I guess the alternative would be special casing line-seq as a transducing source like we do with range?
@noisesmith can you give the range example?
@borkdude it's nothing that would show up in your source code
when range is used in a transducing context, it's optimized - @puredanger described this to me and may be able to provide better info about this than I
I was sure there was a clojure.core fn that lets you walk through every nth element ex. (every? odd? (?core-fn? 2 (range 10)))
@borkdude - I got curious, I think this might be the secret sauce https://github.com/clojure/clojure/blob/f572a60262852af68cdb561784a517143a5847cf/src/jvm/clojure/lang/Range.java#L165
huh, I wonder... is the .reduce(IFn) method called when calling normal "reduce"?
@jcromartie my understanding is that reduce uses it (checking for whether you implement IReduce protocol) as well as transducing contexts
and it's a way to avoid creating lazy-seqs that are not needed
yes indeed, just checked (source reduce)
very nice
that must be new since I last looked at ranges 🙂
they have always been a bit questionable...
the self-reducing versions of range, iterate, cycle, and repeat were added in 1.7 along with transducers
aha, I tagged you by the wrong handle, thanks for chiming in
much blood was spilled to bring you self-reducing range :)
Huge commit this: https://github.com/clojure/clojure/commit/07d6129a9847f62010079ab6f04b7930c2a593e4#diff-82d65e65676f3bcc5f27c32ee14b2dda
http://dev.clojure.org/jira/browse/CLJ-1515 will give you a sense of the work that went into it
I felt silly spending weeks on counting :)
that's pretty great though
but it’s remarkably subtle given that range can return things that are walked per-element, per-chunk, or via self-reduction
and making all of those fast
yeah, it sounds tricky, in terms of retrofitting a core part of the language
seemed like an easy win at first :)
it is interesting to note that none of them actually realizes and holds in memory the actual numbers in the range
hat tip to Rich for that suggestion
I assumed as much, though one can certainly do other things that defeat that thoughtful detail
the cycle,repeat,iterate ones are a bit simpler to understand and had some nice improvements too
There is an old SOAP based webservice i’d like to consume with clj-http. Is it the right library or can someone kindly point me in the right direction.
clj-http will make the HTTP requests for you, but it won't help you construct SOAP XML bodies if that's what you mean
#(comp first (partial sort %))
I would name the function you are about to write "max-by" 🙂
@noisesmith that one is not so efficient
@jcromartie yeah, or just write a reduce
yeah, a reduce would do it
and I think sort-by is what you want, to use a key fn
(first (sort-by keyfn your-coll))
sort accepts an optional comparator
a comparator, yes
but he asked about a key fn
he wants a comparefn not keyfn
oh oops
it's right there. takes a comparator
I thought of sort-by too, but I didn't see him say anything about keyfns
sort takes a comparator, yes
I saw "max-key" and thought keyfn
got it
apparently that is a bowing emoji
I wouldn't have guessed
doesn't a comparator only return :greater :same :less? how do you get a max out of that?
by sorting
using reduce to find a max is better, but for a first shot at it, sort is probably fine
unless you are doing it a whole lot
looks to me like max-key is just a reduce, so you could just wrap the comparator in #(.compare c %1 %2)
found something weird: (set! *warn-on-reflection* true)
(fn [x] (.toString x))
= reflection warning
However, I don’t see why the destructuring is effectively giving a “Object” type hint perhaps
(I’ve always thought it was odd that an Object type hint wasn’t implicit always, but I can see why it may not be the case in the compiler)
my guess is, when all is said and done, the destructuring expands out to a java method call declared to return Object
hiredman yeah, I’ve never seen an automatic discover of an Object method without a hint