This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-26
Channels
- # adventofcode (12)
- # beginners (141)
- # cider (3)
- # cljsrn (3)
- # clojure (76)
- # clojure-russia (1)
- # clojure-spec (7)
- # clojure-uk (4)
- # clojurescript (15)
- # css (1)
- # duct (3)
- # emacs (5)
- # fulcro (85)
- # keechma (1)
- # leiningen (44)
- # off-topic (29)
- # om (6)
- # parinfer (4)
- # perun (1)
- # re-frame (18)
- # reagent (2)
- # ring-swagger (8)
- # shadow-cljs (5)
- # spacemacs (1)
- # sql (7)
Lots of people use str as an alias for clojure.string, because str/lower-case doesn't cause any conflict with the clojure.core/str function.
@souenzzo You can use clojure.core/compare to get a result of -1, 0, or +1 when comparing two #inst's to each other.
>
is for numbers. See also +, *, /, - etc. - in other languages they might be overloaded for other data types but in jvm clojure they are only for numbers
ah, found this:
(defn kebab-case
"Converts CamelCase / camelCase to kebab-case"
[s]
(str/join "-" (map str/lower-case (re-seq #"\w[a-z]+" s))))
@andy.fingerhut: I have n oidea why that works, but yes, it appears that namespace alias str does not collide with buildin function
@qqq When a textual identifier contains a "/" character, the thing before the "/" is tried to be resolved as either a full namespace, or as an alias of a namespace (I don't know off hand which order is checked for between those two). If there is no "/", no part of it is considered a namespace or alias, just a symbol on its own.
meh, can’t come to a solution 😩 I have a lazyseq (file-seq) which I have to iterate through while occasionally change a local data structure (fill and read a hash-table in this loop). Is loop/recur
the right approach?
if you always move through the lazy-seq in order, reduce is simpler / more direct than loop
so it’s okay to work with only one hash-structure for both the “actual” work data and help data?
using one reduce argument to hold both an accumulated result and ancillary data is common
technically it is possible, question is about whether it is a good way of implementation
if you use transduce, you can even specify the function that gets the real result out of the accumulator
@noisesmith yeah, works as expected! didn’t try transduce yet, though
transduce is mainly useful if you are doing some transform on each item as it comes in
eg. replacing (reduce f init (map g coll)) with (transduce (map g) f init coll)
I’m iterating through a list of files keeping some information to exclude duplicates from being inserted into a DB… (file-hash, last-modified, path)
sounds about right - the note about transduce was because including that feature indicates that it’s idiomatic to transform the accumulator to get your value out at the end
one advantage of loop/recur might be, that one can continue the loop from an arbitrary position, whereas with reduce, your nested if-clauses have always to return something…
does it mean if I have a nested structure, that i can’t call “recur” from the most inner level to jump straight into the next iteration?
I should stop talking and try it out myself - I’m concerned that I start explaining my misunderstandings and embarrass myself 😄
well, it's a fairly contrived example, the else branches here are breaking out of the loop
on can’t “break out” of reduce. one has basically to walk though the entire collection…