clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
zhuxun2 2020-11-09T06:08:30.084700Z

What's the idiomatic way to do x.y.z.w += 1 in clojurescript?

valtteri 2020-11-09T06:14:08.086Z

(-> x .-y .-z .-w inc)

zhuxun2 2020-11-09T06:15:34.086600Z

That doesn't sound right to me... inc is pure, isn't it? https://clojuredocs.org/clojure.core/inc

zhuxun2 2020-11-09T06:16:02.087400Z

x.y.z.w is going to be left unchanged

valtteri 2020-11-09T06:16:07.087700Z

Ah sorry you wanted to mutate the value?

valtteri 2020-11-09T06:16:16.088Z

Use set!

zhuxun2 2020-11-09T06:17:31.089200Z

I know, but it's going to be (set! (-> x .-y .-z .-w) (inc (-> x .-y .-z .-w))) which seems kind of mouthful

zhuxun2 2020-11-09T06:18:19.089900Z

I looked and there doesn't seem to be anything like swap! but for properties

valtteri 2020-11-09T06:24:39.091500Z

Mutating properties is probably supposed to be ugly. 😄 I guess that’s what you have. :thinking_face: If you need to do that often, perhaps you could write your own helper macro or function

lassemaatta 2020-11-09T06:26:29.092200Z

can you grab the reference to .w (or .z ) in a let binding and set! that?

zhuxun2 2020-11-09T06:28:59.092900Z

@valtteri Yeah, that makes sense

zhuxun2 2020-11-09T06:29:20.093400Z

@lasse.maatta Seems it would suffice for my case

2020-11-09T10:28:39.095200Z

@zhuxun2 if you are ok with using a library, js-interop has an update-in! macro that would look like (j/update-in! x [.-y .-z .-w] inc) or if the keys are static, (j/update-in! x [:y :z :w] inc) (https://github.com/applied-science/js-interop)

👍 2
borkdude 2020-11-09T19:56:58.097300Z

We have a very strange bug in our advanced CLJS compiled front-end app. We have some specs referring to other specs:

(s/def :foo/foo string?)
(s/def :bar/bar :foo/foo)
All of a sudden this breaks our app:
alpha.cljs:121 Uncaught Error: Unable to resolve spec: :foo/foo
    at u2a (alpha.cljs:121)
    at RY (alpha.cljs:518)
    at tY (alpha.cljs:513)
    at BY (alpha.cljs:314)
    at query.cljs:41

borkdude 2020-11-09T19:57:23.097500Z

CLJS version 1.10.764

borkdude 2020-11-09T19:59:00.097700Z

I don't see this release on github btw: https://github.com/clojure/clojurescript/releases

borkdude 2020-11-09T19:59:37.098100Z

Probably it's better to not load spec at all in our advanced CLJS app

borkdude 2020-11-09T19:59:53.098400Z

we're not instrumenting anything anyway

2020-11-09T20:01:12.098900Z

compile it with :pseudo-names true, it could tell more

borkdude 2020-11-09T20:01:39.099500Z

it just points at spec-impl where it tries to resolve that other spec by name.

borkdude 2020-11-09T20:01:52.099800Z

which it can't find, while it was defined just before.

borkdude 2020-11-09T20:02:57.100500Z

Repro or it didn't happen, I know. It was introduced by a non-related commit in our codebase, so hard to reproduce probably.

2020-11-09T20:05:26.101400Z

with pseudo names, you should be able to debug it in chrome devtools even without source maps, just step through formatted js code

2020-11-09T20:06:05.102200Z

with help of (js-debugger) you can pin-point interesting places

2020-11-09T20:10:52.102800Z

just by chance, aren’t you using multiple javascript contexts? e.g. a webworker and the main page?

borkdude 2020-11-09T20:15:36.103700Z

I think we might have hit some heissenbug. Requiring this namespace earlier in our app seems to get rid of this issue. But still very weird, since these specs are in the same file...

borkdude 2020-11-09T20:16:04.104300Z

we're not using webworkers. anyway, we're getting rid of these specs anyway (in production at least)

lilactown 2020-11-09T23:37:06.105800Z

Are you requiring the namespace that :foo/foo is defd in the namespace that :bar/bar is defd in?

lilactown 2020-11-09T23:37:29.106400Z

It sounds like you’re not

lilactown 2020-11-09T23:40:12.109400Z

When compiled, namespaces are ordered topologically according to who requires who. If you don’t require a namespace, but rely on some global state to be setup in it (like a spec) then there can be orderings where that state isn’t initialized when the code runs