This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-18
Channels
- # alda (8)
- # aws (1)
- # bangalore-clj (1)
- # beginners (55)
- # boot (114)
- # capetown (2)
- # cljs-dev (51)
- # cljsjs (1)
- # cljsrn (14)
- # clojure (119)
- # clojure-belgium (6)
- # clojure-brasil (9)
- # clojure-conj (2)
- # clojure-greece (1)
- # clojure-korea (2)
- # clojure-poland (12)
- # clojure-russia (64)
- # clojure-spec (12)
- # clojure-uk (60)
- # clojurescript (159)
- # code-reviews (2)
- # component (4)
- # core-matrix (2)
- # cursive (79)
- # datascript (7)
- # datomic (2)
- # defnpodcast (4)
- # events (2)
- # hoplon (13)
- # jobs (2)
- # lein-figwheel (1)
- # off-topic (10)
- # om (42)
- # onyx (60)
- # pedestal (5)
- # perun (7)
- # rdf (4)
- # re-frame (4)
- # reagent (21)
- # ring-swagger (25)
- # schema (1)
- # spacemacs (52)
- # specter (1)
- # utah-clojurians (1)
- # yada (5)
A little problem of the clojure koans. The only one that I cannnot solve :
"You can also create a new object from another object with metadata"
(= {:league "National League" :park "AT&T Park"}
(meta (vary-meta giants
assoc {"test" "National Leaque"})))
now I see this error : 'ArityException Wrong number of args (2) passed to: core/assoc--4371 clojure.lang.AFn.throwArity (AFn.java:429)'
You almost got it. To fix the arity exception, drop the curlies.
... assoc "test" "National Leaque" )))
Then you are almost home.Can this be improved :
(fn [key map] (if (contains? map key) (nil? (map key)) false))
There are other ways to write it but most of them are not as succinct
@agile_geek sorry, my English is not very good, What does succint mean
@roelofw most of the other versions are more code and/or not as clear
yes, but if they key is not in the map , I think your code returns ::not-found and it suppose to return false
@agile_geek thanks
@verma (nil? (get map key false))
would probably do the job tho
true... or is that false?
@agile_geek sure, that works as well, get
returning anything other than nil for no key found is good :thumbsup:
You can even drop the get
if map is never nil (fn [key map] (nil? (map key :not-found))
@roelofw a map (the datastructure) is itself a function that takes a key and looks up the value for that key in itself. Also keywords (e.g. :this-is-a-keyword
) are functions that look themselves up in a map.
i.e. ({"key" "this works"} "key") => "this works"
and (:key {:key "this works"}) => "this works"
both work
but this ("key" {"key" "this throws exception"})
doesn't
as "key"
is just a java.lang.String
which doesn't implement IFn
i.e. it's not a function
@agile_geek thanks for the explanation
That's what I like about clojure. Always people who wants to explain things or help with problems
@agile_geek did you ever work with boot and if so, which "ide" do you use ?
@roelofw I've not really used boot, mainly lein and I use Emacs but I have friends who much prefer IntelliJ with Cursive (and some who use Vim and Fireplace or Spacemacs)
However, Emacs is a steep learning curve all of it's own
Oke, I use Cursive but I like to try this framework : https://github.com/framework-one/fw1-clj
There's no reason boot can't be used in Cursive but I've no idea how. Might be worth posting a specific question in the #boot channel?
i.e. "I'm a beginner using Cursive. How do I get started with Boot?"
or conversely ask in the #cursive channel!
it can be done with a trick : https://slack-redir.net/link?url=https%3A%2F%2Fgithub.com%2Fboot-clj%2Fboot%2Fwiki%2FFor-Cursive-Users&v=3
Im stuck at 4clojure , challenge 156 , I have to solve this :
(= (__ 0 [:a :b :c]) {:a 0 :b 0 :c 0})
. I thought this would solve it : (fn [v m](map (assoc % v) m ))
but now the % is unknown