This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-25
Channels
- # announcements (66)
- # aws (1)
- # beginners (60)
- # boot (6)
- # calva (80)
- # cider (3)
- # clj-kondo (14)
- # cljdoc (4)
- # cljs-dev (27)
- # clojure (65)
- # clojure-dev (24)
- # clojure-europe (13)
- # clojure-gamedev (3)
- # clojure-italy (3)
- # clojure-nl (21)
- # clojure-uk (35)
- # clojurescript (98)
- # cursive (25)
- # data-science (3)
- # datomic (10)
- # dirac (16)
- # duct (2)
- # events (2)
- # fulcro (39)
- # jobs-discuss (1)
- # malli (2)
- # other-languages (1)
- # pedestal (26)
- # re-frame (61)
- # reagent (1)
- # reitit (7)
- # shadow-cljs (230)
- # specter (1)
- # tools-deps (28)
- # vim (1)
- # yada (4)
is there a way to make cursive repl use the user namespace by default instead of my-app.core?
My cursive repl has always started me in user
namespace. I wonder if you have some repl middleware configured in your project that might be doing some black magic for you. Totally just a guess.
Is there something like elixirs Enum.take/2
elixir
iex> Enum.take([1, 2, 3], 2)
[1, 2]
Interesting that Elixir's argument order is coll, n
as opposed to n, coll
which feels like it reads better to me: "take n elements of coll"...
i think because of pipe operator they choosed coll first so it can be coll |> Enum.take(2) |> other_func()
Whereas Clojure has (->> coll (take 2))
-- and distinguishes between sequence functions (sequence last) and collection functions (type-preserving, collection first)
For example (subvec [1 2 3] 0 2)
and (conj [1 2] 3), (conj #{1 2} 3)
Whereas (cons 1 [1 2])
-- calls seq
on the argument and also returns a sequence.
huh, i thought that was purely an artifact of lisp
@juan.ignacio848 what is that app in you phone that has cljs repl
Replete I think?
(Replete is what I use on my phone to try stuff out)
i like it thank you for teaching me this @seancorfield
When folks are learning Clojure, they often wonder why some functions seem to take the "collection" first and others take it last -- but it is pretty consistent once you understand the difference between collection (has a type: vector, list, set, hash map, queue, etc) and a sequence (an abstraction that provides elements in order -- sequentially -- even for collections that have no specified order such as sets and hash maps).
(and the various "sequence functions" can accept a collection because they call seq
on it first -- which means they can accept anything that is seqable?
, which includes things like strings etc)
Hey strangers! ๐
Iโm pretty new to Clojure and have been having a hard time finding a readable and/or idiomatic way to create a nested map from two ranges. You can map
or for
or merge
or reduce
. Any suggestions?
The most readable so far has been:
(def rows 2)
(def cols 3)
(def val "")
(apply merge-with merge
(for [row (range rows)
col (range cols)]
{row {col val}}))
The least readable (to me) has been:
(defn value-for-row
[cols]
(->> cols
range
(map #(hash-map % value))
(into {})))
(->> rows
range
(map #(hash-map % (value-for-row cols)))
(into {}))
given the way the rows are constructed, you can just use into {}
instead of apply merge-with merge
I thought that too, but you only get the last value for every outer key with into {}
. It got us both. ๐ณ
the outer keys can occur more than once?
oh, right, they can
but in this context youo can use [x value]
as well (and I'd argue that's more direct / idiomatic as entries in a map are special two-element vectors)
I do like pairs for indices, but you lose certain kinds of queries unless you use a sorted map
(def rows 2)
(def cols 3)
(def val "")
((apply comp
(for [row (range rows)
col (range cols)]
#(assoc-in % [row col] val)))
{})
oh yeah, for sure I would write the reduce version without thinking about it, and have over and over again. I was reaching for something novel, and it superficially is, but I wish I had some cool way to get rid of that for
Is that how youโd write it?
(->> (for [row (range rows), col (range cols)] [row col])
(reduce (fn [m ks] (assoc-in m ks val))
{}))
Yes, but very often in the reduce there is something more complicated then just assoc-in
Thanks @U0NCTKEV8!
not readable at all:
(def rows 2)
(def cols 3)
(def val "")
((->> (range (* rows cols))
(map (juxt #(mod % rows) #(mod % cols)))
(map (fn [entry] #(assoc-in % entry val)))
(apply comp))
{})
I never would have thought of that approach. ๐ Thanks @U0NCTKEV8.
Thatโs art
Warning: componentWillMount has been renamed, and is not recommended for use. See for details.