This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-08
Channels
- # adventofcode (31)
- # beginners (97)
- # bigdata (2)
- # boot (276)
- # cider (17)
- # cljsrn (5)
- # clojure (150)
- # clojure-china (3)
- # clojure-conj (8)
- # clojure-greece (1)
- # clojure-india (1)
- # clojure-korea (1)
- # clojure-new-zealand (4)
- # clojure-russia (40)
- # clojure-spec (119)
- # clojure-uk (116)
- # clojurescript (87)
- # code-reviews (110)
- # core-async (4)
- # cursive (11)
- # datomic (26)
- # garden (4)
- # gorilla (7)
- # hoplon (82)
- # humor (1)
- # jobs (2)
- # jobs-discuss (10)
- # luminus (17)
- # onyx (60)
- # planck (2)
- # play-clj (2)
- # protorepl (70)
- # re-frame (121)
- # reagent (7)
- # ring-swagger (3)
- # rum (16)
- # test-check (16)
- # untangled (12)
- # yada (20)
@ryanlabouve: as a beginner to programing and clojure I would go with clojure the brave and clojure from the ground up
I think joy of clojure and clojure applied are great when you want to build your own projects
Thanks! Very eager to to get to both joy of Clojure and Clojure applied. Reading their TOC makes me want to read as fast as possible 😛 By "Clojure from the ground up" do you mean https://aphyr.com/tags/Clojure-from-the-ground-up ?
👍 for Clojure Applied.. I'm not author and @alexmiller has not bribed me!
oh also 👍 for @ericnormand's courses!
I went with Clojure for the Brave and True, and did the 4Clojure exercises (sorted by difficulty) at the same time as reading it. Worked well!
I also think the cheat sheet is great for exploring the many clojure.core functions as they are divided into categories: http://clojure.org/api/cheatsheet
i know it has something to do with exporting (making the function available) for something else, but for what and when it is used?
@ashnur Some info here http://www.luminusweb.net/docs/clojurescript.md#advanced_compilation_and_exports
@ashnur it protects the name from getting minified so you can call it by name from Javascript
I have these code : https://slack-redir.net/link?url=https%3A%2F%2Fgithub.com%2Frwobben%2Fpaintings&v=3
(defn wimble [m k] (map #(k %) m))
(wimble [1 2] (partial + 1))
(map (partial + 1) [1 2])
speaking of brave and true -- I'm working through chapter5 trying to implement my own assoc-in
with recur:
; 3. Implement the assoc-in function. Hint: use the assoc function and
; define its parameters as [m [k & ks] v].
(defn my-assoc-in
[m [k & ks] v]
(loop [new-map m
k k
ks ks]
(if (empty? ks)
(assoc new-map k v)
(recur (k new-map) (first ks) (rest ks)))))
This works for the base case of just one key (ks starts empty) but the recursion only returns the deepest level of the map where we set the value. I can't seem to figure out how to drill down to set the value like it's doing but doing that with the entire original map. Suggestions?Your fixed point is only going to fire when ks is empty. So its only ever going to assoc the last value.
Ah, recur is in the else position… did not see that. But you need to be “assoc’ing” at each level. In this case you are “throwing away” the nested levels as you progress inside.
so I can put assoc in the recur, but then how do I do that final "deep/nested" assoc?
hey guys, using (apply map vector <col>)
produces a list e.g (a b c)
what is the equivalent to return the result as a vector?
@jeffh-fp I'm actually not sure if you can use recur
(which needs to be in the tail position) to do that. You'll probably want to use "classical" recursion in which you explicitly call your function
[[6 0 0 0 0 0 1 5 0] [9 5 4 7 1 0 0 8 0] [0 0 0 5 0 2 6 0 0] [8 0 0 0 9 4 0 0 6] [0 0 3 8 0 5 4 0 0] [4 0 0 3 7 0 0 0 8] [0 0 6 9 0 3 0 0 0] [0 2 0 0 4 7 8 9 3] [0 4 9 0 0 0 0 0 5]]
the aim is to return columns by taking the 1st position of each column then the 2nd and so forth
to get this ([6 9 0 8 0 4 0 0 0] [0 5 0 0 0 0 0 2 4] [0 4 0 0 3 0 6 0 9] [0 7 5 0 8 3 9 0 0] [0 1 0 9 0 7 0 4 0] [0 0 2 4 5 0 3 7 0] [1 0 6 0 4 0 0 8 0] [5 8 0 0 0 0 0 9 0] [0 0 0 6 0 8 0 3 5])
but as a vector
if input is a seq, maybe mapv takes a while to go to vector, so there's benefit of just realizing the sequence you want from the first
I was expecting the answer to be (true false true)
but instead it is (true true true)
yep @curlyfry I got it I think:
(defn my-assoc-in
[m [k & ks] v]
(if (empty? ks)
(assoc m k v)
(assoc m k (my-assoc-in (get m k) ks v))))
@jeffh-fp If you're curious, you can look in the clojure.core implementation of assoc-in
to see how they did it
not sure why I felt like I had to use recur
-- that had me stumped for a while but I learned a bit more about recur 🙂
doesn't seem to work with vectors:
(def users [{:name "James" :age 26} {:name "John" :age 43}])
;; update the age of the second (index 1) user
(my-assoc-in users [1 :age] 44)
breaks with ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn chapter5/my-assoc-in (chapter5.clj:56)