Fork me on GitHub
#cljs-dev
<
2022-02-28
>
p-himik13:02:20

Looks like a bug in CLJS compiler, and I couldn't find anything related in Jira: https://ask.clojure.org/index.php/11607/binding-js-variable-to-variable-binds-nil

dnolen14:02:41

@p-himik it's a variant of a known issue around locals, shadowing, and js globals

👍 1
dnolen14:02:59

@p-himik @lilactown are you both trying this at the top-level though?

dnolen14:02:32

top-level is maybe somewhat tricky to handle and not a high priority

p-himik14:02:35

It's actually @pez that was using it, not me.

pez17:02:37

@dnolen it was in a let-box in a defn.

dnolen17:02:07

what is let-box?

dnolen17:02:26

the examples thus far are not so meaningful

dnolen17:02:40

and the test at the REPL not so meaningful because of what i said about the top-level

borkdude17:02:51

he means a let binding in a defn (I think)

dnolen17:02:23

so we need to see something more minimal but complete inside of defn

dnolen17:02:59

window is in the global shadow set, so already this is strange

lilactown17:02:34

literal code was

(defn start!
  []
  (let [window (js/window.open "" "" "")
        container (.. window -document (createElement "div"))]
    window))

lilactown18:02:23

i eval'd this at the REPL, then tried to call it (start!)

dnolen19:02:00

@lilactown that's better thanks 🙂 people do top-level let so it wasn't clear

Sam Ritchie19:02:05

Would a patch be welcome with something like

(core/defmacro js-exponentiate [base exponent]
  (core/list 'js* "~{} ** ~{}" base exponent))
The goal would be to replace the js* call in (js* "~{} ** ~{}" (js/BigInt 10) (js/BigInt 2)) , since Math/pow can’t exponentiate bigint instances

dnolen20:02:43

hrm ... does clojure.math provide something here? \cc @quoll ^

dnolen20:02:41

@sritchie09 are ** and Math/pow semantically the same other than the boundary across types?

Sam Ritchie20:02:29

according to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation, It is equivalent to Math.pow, except it also accepts BigInts as operands.

dnolen20:02:08

@sritchie09 it would be preferable for this to be in clojure.math then

👍 1
quoll23:02:54

I have been looking to expand cljs-math to BigInt, but it's still a work in progress. Sam’s suggestion seems good at face value

Sam Ritchie23:02:28

I believe @dnolen and @quoll that an older version of the closure compiler didn’t like **, which led to me make this PR to Fraction.js before understanding this fully: https://github.com/infusion/Fraction.js/pull/43#issuecomment-881054662 we should be okay now with the version cljs uses.