This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-15
Channels
- # adventofcode (121)
- # bangalore-clj (5)
- # beginners (46)
- # boot-dev (9)
- # cider (20)
- # cljs-dev (7)
- # cljsrn (1)
- # clojure (341)
- # clojure-austin (7)
- # clojure-greece (144)
- # clojure-india (3)
- # clojure-italy (5)
- # clojure-spain (1)
- # clojure-spec (34)
- # clojure-sweden (3)
- # clojure-uk (90)
- # clojurescript (24)
- # core-async (1)
- # core-logic (7)
- # cursive (108)
- # datascript (2)
- # datomic (39)
- # events (1)
- # fulcro (225)
- # graphql (8)
- # hoplon (86)
- # instaparse (12)
- # jobs-discuss (2)
- # jvm (4)
- # keechma (1)
- # lein-figwheel (2)
- # leiningen (12)
- # off-topic (26)
- # onyx (35)
- # other-languages (1)
- # pedestal (3)
- # planck (11)
- # re-frame (12)
- # reagent (12)
- # reitit (5)
- # spacemacs (48)
- # specter (29)
- # sql (2)
- # test-check (1)
- # unrepl (71)
@admay require?
Hey guys, I'm wondering in the clojure world, what exactly do people mean when they say "s expression"
Is that just any form in parentheses that gets evaluated?
or not; just anything in parentheses (i.e. quoted lists are still s-expressions). emacs' idea of s-expression is really just "matched delimiters with stuff inside".
is it possible to apply a patch or use a local git repo to satisfy a leiningen dependency?
checkout deps were mentioned, but FYI it’s much simpler to just use lein install
to make the lib locally available - in fact doing this is a prerequisite for using checkouts. The advanatage of checkouts is easy reloading of changes to the library without repl restarts. If you are not developing the library actively, just use lein install
since there’s no method that doesn’t require this, and it’s sufficient if you are not changing the code actively.
@adamvh Look for checkout dependencies
(I don't use Leiningen any more but I'm pretty sure it supports that)
Hi! I'm doing a mini coding problem where we want to collapse a string with potentially repeating characters into a smaller representation. For example, given "aaaabbbb" we would return "4a4b". My current implementation does a lot of ugly loop/recur things, and I'm wondering if anyone could suggest an elegant way to do this in a single pass over the input sequence. My instinct would be to reach for transducers in some way (somehow do repeated take-while's), but i'm not sure how that might look. Thanks!
@quang You could do it by splitting the string into characters, using partition-by with the identity function, using reduce to conj the length of the partition and the first element out of each partition, then joining the result. I prefer this kind of code to manual iteration, but others may have a different approach.
^ sorry wrong mention. Meant @quan.ngoc.nguyen
(map (juxt count first) p)
would do that with a single pass.
(well, almost the same... but you ultimately want a string...
(str/join (map (comp (partial apply str) (juxt count first)) (partition-by identity "aaaabbbb")))
might do it
Yeah, that seems to work...
boot.user=> (require '[clojure.string :as str])
nil
boot.user=> (str/join (map (comp (partial apply str) (juxt count first)) (partition-by identity "aaaabbbb")))
"4a4b"
thank you all for the help! looks like the partition-by here was the key idea for the single-pass constraint i was looking for 🙂
Hi folks. I'm somewhat new and I've run into a wall with a configuration problem. I've got a lein project which suddenly isn't able to resolve a single dependency (the others have been fetched fine):
Could not find artifact net.mikeria:core.matrix:jar:0.61.0 in central ( )
Could not find artifact net.mikeria:core.matrix:jar:0.61.0 in clojars ( )
This could be due to a typo in :dependencies, file system permissions, or network issues.
If you are behind a proxy, try setting the 'http_proxy' environment variable.
This is persisting across multiple internet connections and computers. Does anyone have any guidance to offer in troubleshooting?@quan.ngoc.nguyen You certainly could do it with a stateful transducer too. That would be faster I expect, but more code...
@naylyn.gaffney Try net.mikera
-- you have an extra i
in there.
A fresh set of 👀 often helps!
@seancorfield is your suspected performance improvement because we wouldn't be creating intermediate seqs?
@quan.ngoc.nguyen Right, and using volatile!
state in the transducer to track where you were in the sequence -- pretty much the old, imperative way but unrolled into the phases of transduction.
sweet, that makes sense. Thank you for explaining all of that to me 🙂
You could also just leverage the transducer-returning arities of map
and partition-by
to avoid the lazy sequence construction...
boot.user=> (time (dotimes [n 100000] (transduce (comp (partition-by identity) (map (juxt count first)) (map (partial apply str))) str "" "aaaabbb")))
"Elapsed time: 372.182 msecs"
nil
boot.user=> (time (dotimes [n 100000] (str/join (map (comp (partial apply str) (juxt count first)) (partition-by identity "aaaabbbb")))))
"Elapsed time: 558.569 msecs"
You can avoid the (map (partial apply str))
if you use (mapcat (juxt count first))
instead.
Ah, yes! Good catch!
Here's another option
boot.user=> (time (dotimes [n 100000] (str/join (into [] (comp (partition-by identity) (map (juxt count first)) (map (partial apply str))) "aaaabbb"))))
"Elapsed time: 318.513 msecs"
Repeat timings suggest the transduce
version is probably faster. But this is another use of the transducer-returning map
and partition-by
aritiesoh yeah i just tried it out independently and the code came out to be about the same
it's cool that the timings support the performance improvement
Something that can be used to stream-read from a file, that can be used within a transducing process? (meaning e.g. composed with other transducers)
(defn text-file-reader [filepath reader]
(with-open
[file-reader (reader filepath)]
(line-seq file-reader)))