Fork me on GitHub
#beginners
<
2019-10-25
>
vale05:10:01

is there a way to make cursive repl use the user namespace by default instead of my-app.core?

skuttleman18:10:19

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.

m373h4n19:10:17

Is there something like elixirs Enum.take/2

elixir 
iex> Enum.take([1, 2, 3], 2)
[1, 2]

seancorfield19:10:19

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"...

m373h4n19:10:28

i think because of pipe operator they choosed coll first so it can be coll |> Enum.take(2) |> other_func()

juan.ignacio84819:10:18

That works like ->?

seancorfield19:10:40

Whereas Clojure has (->> coll (take 2)) -- and distinguishes between sequence functions (sequence last) and collection functions (type-preserving, collection first)

seancorfield19:10:38

For example (subvec [1 2 3] 0 2)

m373h4n19:10:56

yes it's similiar to -> gets previous functions result as first argument

seancorfield19:10:28

and (conj [1 2] 3), (conj #{1 2} 3)

seancorfield19:10:33

Whereas (cons 1 [1 2]) -- calls seq on the argument and also returns a sequence.

nbtheduke19:10:57

huh, i thought that was purely an artifact of lisp

m373h4n19:10:55

@juan.ignacio848 what is that app in you phone that has cljs repl

seancorfield19:10:09

Replete I think?

seancorfield19:10:38

(Replete is what I use on my phone to try stuff out)

m373h4n19:10:13

thanks ๐Ÿ™‚

juan.ignacio84819:10:16

It's available for Android and iOS

m373h4n19:10:42

i like it thank you for teaching me this @seancorfield

seancorfield19:10:27

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).

seancorfield19:10:18

(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)

sean.poulter21:10:50

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 {}))

noisesmith21:10:04

given the way the rows are constructed, you can just use into {} instead of apply merge-with merge

sean.poulter00:10:51

I thought that too, but you only get the last value for every outer key with into {}. It got us both. ๐Ÿ˜ณ

noisesmith17:10:25

the outer keys can occur more than once?

noisesmith17:10:48

oh, right, they can

noisesmith21:10:02

also I would replace #(hash-map % value) with (fn [x] {x value})

noisesmith21:10:35

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)

hiredman21:10:11

I do like pairs for indices, but you lose certain kinds of queries unless you use a sorted map

hiredman21:10:30

(def rows 2)
(def cols 3)
(def val "")


((apply comp
        (for [row (range rows)
              col (range cols)]
          #(assoc-in % [row col] val)))
 {})

dpsutton21:10:05

that's reduce through squinted eyes there

dpsutton21:10:36

and i would never have thought of that

hiredman21:10:03

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

sean.poulter00:10:59

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))
             {}))

hiredman01:10:07

Yes, but very often in the reduce there is something more complicated then just assoc-in

hiredman21:10:47

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))
 {})

sean.poulter00:10:29

I never would have thought of that approach. ๐Ÿ˜† Thanks @.

nbtheduke21:10:55

Thatโ€™s art

papachan23:10:26

Someone knows how to remove theses warnings from react?

papachan23:10:57

Warning: componentWillMount has been renamed, and is not recommended for use. See  for details.

papachan23:10:41

i suppose they appeared when i upgrade react package version

lilactown23:10:28

@papachan are you using reagent?

papachan23:10:19

Well i instance reagent from code yes. but i am using shadow-cljs

lilactown23:10:50

sure. reagent is the reason that youโ€™re seeing those warnings

lilactown23:10:08

the library uses some React lifecycles that are being deprecated

papachan23:10:26

oh didnt know

papachan23:10:59

but its the first time i see that. <o>

lilactown23:10:20

right, you said you updated React. in the new version of React, those lifecycles are deprecated

papachan23:10:43

do you know which version i have to run?

lilactown23:10:01

you can keep using it, but you will see those warnings. it still works

lilactown23:10:40

the next version of reagent will address this

papachan23:10:19

oh good to know. thank you !