Fork me on GitHub
#clojure
<
2021-03-28
>
piotrts14:03:10

Just curious:

(for [elem [1 2 3]
      :let [elem+1 (inc elem)]]
  elem+1)
=> (2 3 4)
but
(for [:let [elems [2 3 4]]
      elem elems]
  elem)
Syntax error macroexpanding for at (core.clj:12:1).
Can't pop empty vector
is there a reason behind this behaviour? I think :let here makes sense

borkdude14:03:19

I think there is a JIRA issue for it somewhere, but not very high priority, maybe even rejected. Just use a surrounding let in this case.

piotrts14:03:28

yep, this is what I am doing

ayushka14:03:44

Can anyone recommend a lib for managing datomic schema migrations with the client api library?

vncz16:03:03

Does anybody have a better idea on how to write this?

p-himik16:03:31

I think it's just fine. Personally, I'd split the condition and the assoc into two lines.

borkdude16:03:53

Minor thing: I tend to use identical? on keywords, but = also works

p-himik16:03:22

Not cross-platform.

p-himik16:03:37

ClojureScript 1.10.773
cljs.user=> (def x :x)
#'cljs.user/x
cljs.user=> (identical? x :x)
false

vncz16:03:06

I guess what I'm asking if it's ok to use cond-> to "simulate" something like if (cond) return f(a) else a

vncz16:03:51

This is the entire function in case it helps

borkdude16:03:13

@U2FRKM4TW Since this is the #clojure identical? is appropriate, in CLJS you use keyword-identical?, good to be aware

👆 3
p-himik16:03:20

IMO that's exactly what it was created for. It supports a bit more, but that's OK use only a part of this potential.

p-himik16:03:12

FWIW I use cond-> in such scenarios all the time. :)

borkdude16:03:21

You should probably be using the clojure.spec.alpha/invalid? function though, the keyword may be an implementation detail

vncz16:03:44

@U04V15CAJ makes sense, I'll change it

walterl19:03:39

I'd use the shorter ::spec/invalid form of the keyword (and split up the lines as @U2FRKM4TW suggested). Otherwise LGTM 👍

vncz13:03:09

Thanks everybody for the advices. More snippets will come here :)