This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-07-29
Channels
- # admin-announcements (48)
- # announcements (1)
- # beginners (80)
- # boot (150)
- # cljs-dev (12)
- # clojure (133)
- # clojure-dev (1)
- # clojure-italy (27)
- # clojure-japan (1)
- # clojure-russia (77)
- # clojurescript (236)
- # clojutre (3)
- # code-reviews (1)
- # core-async (14)
- # core-logic (4)
- # core-matrix (15)
- # cursive (5)
- # datomic (30)
- # editors (16)
- # events (1)
- # hoplon (1)
- # ldnclj (17)
- # off-topic (30)
- # om (2)
- # onyx (47)
- # reagent (8)
@chris: I like Speclj, as their autorunner is great
But in general I think clojure.test, midje, and speclj are the main choices
Hi all, I'm struggling with this ... I'd like to take a tree-like structure like this: {"foo" {"bar" "1" "baz" "2"}}
and recursively traverse while remembering the path from the root in order to produce something like this: ["foo/bar/1", "foo/baz/2"]
. Any suggestions?
I've played around with clojure.walk but I get stuck because not able to keep track of where I am in the tree, maybe there's a way to do clojure.walk and maintain some context?
you should look at clojure zippers
@upgradingdave: this might help http://josf.info/blog/2014/03/21/getting-acquainted-with-clojure-zippers/ Be aware that you will have to provide an fn when you create the zipper so it can recognise a node. map? might be sufficient based on your example.
@colin.yates: I came across zippers and they look really interesting, looking forward to digging deeper, thx for the link 😉
if I want to remove
from a map, is there a more idiomatic way than (into {} (remove (fn [[k v]] (predicate? k)) coll)
?
I don’t know which one is more idiomatic, but at first glance, I would know what dissoc is doing to a map. While the other snippet requires a little bit more effort.
I do like that, as you point out, dissoc
is clear as to what is really happening. remove
creates (at least notionally; not sure about actually) a list of vectors that then go into a map again.
I haven't seen a lot of letfn
s in the wild... is that because they're not common, or I'm not looking at the right code?
@curtosis: I think the general consensus is that you only use it when you need to let a recursive function. No reason in particular as far as I can tell. Just the way it’s come about for idiomatic clojure.
Lisp-1 vs. Lisp-2 is probably a contributing factor.
Interesting. I tend to use it for fns I use in map
etc. calls... instead of, say, (fn [x] (contains? s (:id x))
I'll close over s
and give it a name. Especially when it's more than a line or two.
ah, that would get to @pataprogramming 's point. I never thought of doing it in a let. 😉
I could go either way on it, then.... letfn
communicates intent better, but is essentially noise (= additional enclosing form)
Right. Early on I certainly preferred letfn
because I find it more explicit. After working in a clojure codebase for a couple of years, I’ve reverted to let
simply because it’s more idiomatic.
cursive also annoyingly indents to the args under letfn
and I haven't found the setting to fix it. This may be dispositive.
Naming inline (fn foo? [x] ...)
can be helpful, both for intent and stacktraces. Doesn't help with longer functions, though.
That is, it doesn't help make the code read more cleanly for multi-line lambdas, which are still messy.
I’m ocd about having small functions, that is why I don’t use letfn
. I’m a total newbie and still finding my way, so maybe I need to get over my obsession with small functions.
ISTR something recently about why there's not-any?
but not any?
... ring a bell? do I just use (complement not-any?)
?
@roberto: It’s actually really interesting that my clojure fns tend to be much longer than, say, my java methods. I was obsessive in java about making my methods just a few lines. But in clojure, I routinely (map … (filter … (map … coll)))
without a second thought.
Truthiness punning is idiomatic for most predicates. There's nothing sensible to return for not-any?
, but there is for some
. The naming is not the best, I'd agree.
As long as you aren't trying to remove logically false values, which is what I vaguely recall was an argument for the existence of any?
.
As in, you need to use apply
? The above removes all items from coll
that have at least one :ids
matching my-pred?
.
sorry, bad choice of word. I want to remove all items from coll that have at least one element in :ids for which my-pred?
is true.
not yet. I've got a different logic bug I'm puzzling through. I'm translating some Scala code that is a (groupBy (filterNot (groupBy (exists (forall (contains s x))))))
Well, feel free to holler if you get stuck Let me know if the above works for you when you get around to it.
@potetm: here's what it ended up as. https://gist.github.com/curtosis/06c415f03115de06e676