clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
piotrts 2021-03-28T14:04:10.042400Z

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

borkdude 2021-03-28T14:05:19.042800Z

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.

piotrts 2021-03-28T14:06:28.043100Z

yep, this is what I am doing

2021-03-28T14:09:44.043900Z

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

vncz 2021-03-28T16:09:56.044Z

vncz 2021-03-28T16:10:03.044300Z

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

vncz 2021-03-29T13:53:09.058600Z

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

p-himik 2021-03-28T16:19:31.044400Z

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

borkdude 2021-03-28T16:19:53.044600Z

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

p-himik 2021-03-28T16:21:22.044800Z

Not cross-platform.

p-himik 2021-03-28T16:21:37.045Z

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

vncz 2021-03-28T16:27:06.045200Z

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

vncz 2021-03-28T16:27:51.045400Z

This is the entire function in case it helps

borkdude 2021-03-28T16:28:13.045600Z

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

👆 1
vncz 2021-03-28T16:28:13.045800Z

p-himik 2021-03-28T16:28:20.046Z

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-himik 2021-03-28T16:28:48.046200Z

@borkdude Sure.

p-himik 2021-03-28T16:29:12.046400Z

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

borkdude 2021-03-28T16:29:21.046600Z

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

vncz 2021-03-28T16:35:44.046800Z

@borkdude makes sense, I'll change it

walterl 2021-03-28T19:47:39.047500Z

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