Fork me on GitHub
#clojurescript
<
2021-12-26
>
Sam Ritchie13:12:29

potential cljs bug from “1.10.773”? let-binding /

(let [/ clojure.core//]
  (/ 10 2))
results in
/Users/sritchie/code/clj/sicmutils/.shadow-cljs/builds/test/dev/out/cljs-runtime/sicmutils.util.permute.js:318
var ._28164 = cljs.core._SLASH_;

SyntaxError: Unexpected token '.'
    at new Script (node:vm:100:7)
    at createScript (node:vm:258:10)
    at Object.runInThisContext (node:vm:306:10)
    at global.SHADOW_IMPORT (/Users/sritchie/code/clj/sicmutils/target/main/node-tests.js:56:15)
    at /Users/sritchie/code/clj/sicmutils/target/main/node-tests.js:1840:1
    at Object.<anonymous> (/Users/sritchie/code/clj/sicmutils/target/main/node-tests.js:2036:3)
    at Module._compile (node:internal/modules/cjs/loader:1109:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
    at Module.load (node:internal/modules/cjs/loader:989:32)
    at Function.Module._load (node:internal/modules/cjs/loader:829:14)

Chase23:12:17

So I'm exploring clj/js interop and I create a js object in my cljs file like:

(def student #js {"locker" 212
                  "grades" {"Math" "A",
                            "Physics" nil,
                            "English" "A+"}})
and then in the same cljs file I updated the physics grade with: (set! (.. student -grades -Physics) "B") So cljs is immutable so when I now evaluate student in the repl I see that "Physics" is still nil but I'm seeing conflicting things in the browser console:

Chase23:12:53

It seems like it is telling me it is null but also telling me its "B"?

p-himik23:12:34

#js is shallow.

p-himik23:12:07

To get nested JS objects/arrays, you have to add #js in front of each and every one.

emccue00:12:07

(def student #js {"locker" 212
                  "grades" #js {"Math" "A",
                                "Physics" nil,
                                "English" "A+"}})

Chase00:12:58

ahh, ok. And if I didn't want to do that I could just go with (clj->js {"locker" ...}) , right?

emccue00:12:54

that would have a runtime cost, but yes