This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-11
Channels
- # admin-announcements (3)
- # beginners (51)
- # boot (14)
- # cider (55)
- # cljsrn (5)
- # clojure (105)
- # clojure-austin (2)
- # clojure-brasil (3)
- # clojure-dusseldorf (2)
- # clojure-greece (5)
- # clojure-italy (1)
- # clojure-mexico (1)
- # clojure-russia (74)
- # clojure-spec (66)
- # clojure-uk (22)
- # clojurescript (124)
- # cursive (10)
- # datomic (79)
- # events (2)
- # immutant (3)
- # jobs (4)
- # klipse (38)
- # leiningen (2)
- # luminus (1)
- # off-topic (25)
- # om (48)
- # om-next (36)
- # on (1)
- # onyx (19)
- # overtone (3)
- # pedestal (2)
- # proton (3)
- # re-frame (178)
- # reagent (49)
- # ring-swagger (1)
- # spacemacs (10)
- # specter (29)
- # testing (5)
- # untangled (6)
- # yada (65)
Hey guys! I have used the emacs-config that can be found at http://www.braveclojure.com/basic-emacs/ However, it doesn't seem to have auto-indent activated. Could someone help a emacs-noob like me with this setting? Where do I make this setting, and what to set so my code is automatically indented correctly? Thanks in advance. đ
Hi all, I have a function that takes three params, two of which are optional (the optional params are sent as nil
when not applicable in this case). In my function, I want to call another function with the optional params passed as a map, while not including any param that is nil
. What is an idiomatic way to build this map? My ugly solution uses conditional logic like (when p1 (assoc some-map :p1 p1))
Are you familiar with multi-arity functions?
(defn foo [arg1 arg2 arg2]
(let [m (into [] (remove nil [arg1 arg2 arg3]))]
(the-fn m)))
@manutter51: Yes I have used them in the past. Might fit my use case.
@schmee: That makes sense, seems pretty clean. Would the better approach be (if I am able to modify the caller here) using multi-arity functions as @manutter51 suggests?
Actually, the multi-arity part doesnât relate directly to the question youâre asking, but you might want to make it part of what you build anyway
You might also use zipmap
plus filter
bsiver I would probably make it the callers responsibility to construct the hash and pass it in directly
Hah right, perhaps I overgeneralized a bit too much here. But I really appreciate the advice nonetheless.
@bsiver check out my snippet, it takes your function args and turns them into a map, omitting any missing args
some random advice:
- donât encode information through order, i.e. don't use [opt1 opt2]
, but rather {:opt1 :foo :opt2 :bar}
- try to avoid using nil
to encode optional values
@manutter51 Thanks, that is nice and succinct. I am presuming (filter identity)
is an idiomatic way of returning a value if itâs non-nil?
The filter function takes a predicate function and a seq, and returns all the items in the seq for which the predicate returns âtruthyâ
and identity
just returns whatever you pass it
Thatâs true, you have to watch out for this:
(remove nil? coll)
is better
manutter51âs example does what I donât like doing: it encodes information through order
Thatâs true too. You can get away with order-of-args for one or two args, maybe as many as 3
More than three, you should definitely use a map
why is there a distinction between bigint and biginteger? why does the former exist if the latter has been in the jvm since 1.1?
@williewillus: I didnât know the answer myself, but I found this helpful StackOverflow answer: http://stackoverflow.com/a/18024386/491897
Seems the main reasons for the clojure version are that its hashcode is consistent with Long
s, and they are more performant in that theyâll use primitives to represent their values when possible.
thanks!
Hello, how possible redirect to an URI with parameters? like
(->(ring.util.response/redirect â/addâ) (assoc :add data))