clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
tomrbowden 2021-02-25T06:08:27.083200Z

Is it possible to use the JavaScript operators typeof or delete via interop with CLJS?

p-himik 2021-02-25T06:30:39.083300Z

Not via interop. But you can use js-delete and goog/typeOf.

👍 1
tomrbowden 2021-02-25T06:36:34.083500Z

@p-himik Thank you!

👍 1
borkdude 2021-02-25T19:02:26.084100Z

Is there a way to make this work in CLJS?

cljs.user=> (let [x IDeref] (satisfies? x (atom 0)))
false

NoahTheDuke 2021-02-25T20:55:08.091500Z

whoops, wrong channel. 😬

lilactown 2021-02-25T20:59:07.091600Z

reading the source of the satisfies? macro, it looks like it relies on using the analyzer to get the name of the protocol so that it knows what attribute to look up on the object being checked

lilactown 2021-02-25T20:59:36.091800Z

in order to change this, I think you would have to emit the name of the protocol in code somewhere where you could read it at runtime

borkdude 2021-02-25T21:01:00.092100Z

yeah, I worked around this by using cond = on the protocol object and then hardcoding the satisfies...

lilactown 2021-02-25T21:01:13.092300Z

I think that's your best bet

lilactown 2021-02-25T21:02:04.092500Z

emitting the name in code and trying to use it at runtime, would break advanced optimizations where the attribute on the object gets renamed. emitting the check via a macro ensures that the check stays coherent after optimization

lilactown 2021-02-25T21:02:58.092700Z

we could tell GCC not to optimize protocols but I don't think we want that 🙂