Fork me on GitHub
#beginners
<
2017-01-11
>
roelof06:01:12

any one who is experienced in spec has a idea why this happens ?

roelof13:01:31

A other question. I want to display on the home-page some pagination with numbers.

roelof13:01:48

Now the numbers depend on the page the visitor is.

roelof13:01:21

Can I do this with only selmer or do I have to use some sort of function ?

peter.d14:01:37

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

bsiver20:01:04

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

manutter5120:01:59

Are you familiar with multi-arity functions?

schmee20:01:13

(defn foo [arg1 arg2 arg2]
  (let [m (into [] (remove nil [arg1 arg2 arg3]))]
    (the-fn m)))

schmee20:01:32

but I don’t recommend passing optional argument with nil in this fashion

bsiver20:01:55

@manutter51: Yes I have used them in the past. Might fit my use case.

schmee20:01:56

sry, into {}

bsiver20:01:43

@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?

manutter5120:01:28

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

bsiver20:01:10

Gotcha, thanks for the suggestions

manutter5120:01:25

You might also use zipmap plus filter

schmee20:01:43

bsiver I would probably make it the callers responsibility to construct the hash and pass it in directly

schmee20:01:03

something like

(defn foo [arg1 opts]
  (the-fn opts))

schmee20:01:33

but of course it’s hard to specific advice without knowing the specifics 🙂

bsiver20:01:02

Hah right, perhaps I overgeneralized a bit too much here. But I really appreciate the advice nonetheless.

manutter5120:01:27

@bsiver check out my snippet, it takes your function args and turns them into a map, omitting any missing args

schmee20:01:44

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

schmee20:01:58

but of course there are exception to these rules etc. etc...

bsiver20:01:04

@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?

manutter5120:01:29

The filter function takes a predicate function and a seq, and returns all the items in the seq for which the predicate returns “truthy”

manutter5120:01:42

and identity just returns whatever you pass it

schmee20:01:46

I’d use (remove nil? coll) instead

schmee20:01:58

there is no doubt about what that does

bsiver20:01:03

I will admit the latter reads more clearly to a noob like me

manutter5120:01:11

That’s true, you have to watch out for this:

manutter5120:01:13

(remove nil? coll) is better

schmee20:01:19

manutter51’s example does what I don’t like doing: it encodes information through order

schmee20:01:27

which of the arguments is which in args?

schmee20:01:31

how do you know?

manutter5120:01:54

That’s true too. You can get away with order-of-args for one or two args, maybe as many as 3

manutter5120:01:08

More than three, you should definitely use a map

schmee20:01:16

“five, is right out"

schmee20:01:49

I’m happy you guys understood that reference

bsiver20:01:01

Surprisingly it translates well through the internet

williewillus22:01:13

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?

bsiver22:01:45

@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 Longs, and they are more performant in that they’ll use primitives to represent their values when possible.

bsiver23:01:44

Definitely a place where the BigInt docstring could use some explanation imo

sb23:01:42

Hello, how possible redirect to an URI with parameters? like

(->(ring.util.response/redirect “/add”) (assoc :add data))

sb23:01:13

that isn’t works for me now.. I call from a function, not from "defroutes"

sb23:01:41

or how possible define the prev route dependencies? like if come from this “url/route” then “ok”, but if come any else then drop to “/..”?

sb23:01:46

thanks in advance

sb23:01:28

not with ring.util.codec/form-encode method if that is possible