Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by
In bootstrap, the macro form of {{cljs.core/-}} is evidently available as {{_}} so, for example (_ 7 3) works.

Repro:


cljs.user=> (require 'cljs.js)
nil
cljs.user=> (cljs.js/eval-str (cljs.js/empty-state)
  "(_ 7 3)" nil {:eval cljs.js/js-eval :context :expr} identity)
{:ns cljs.user, :value 4}

5 Answers

0 votes
by
_Comment made by: slipset_

So, in self-hosted (at least) the munged names are available, you can see this for `+` as well

cljs.user=> (_PLUS_ 4 4)
8


(in-ns 'cljs.js)
nil
cljs.js=> (compile-str (empty-state) "(+ 4 4)" nil identity)
{:value "((4) + (4));\n"}
cljs.js=> (compile-str (empty-state) "(_PLUS_ 4 4)" nil identity)
{:value "((4) + (4));\n"}
cljs.js=>


With a special `ns-interns**` as

(defn ns-interns**
  "Bootstrap only."
  [sym]
  (let [ns-obj (find-ns-obj sym)
        ns     (Namespace. ns-obj sym)]
    (letfn [(step [ret k]
              (let [var-sym (symbol k #_(demunge k))] ;; not demunging the key
                (assoc ret
                  var-sym (Var. #(gobject/get ns-obj k)
                            (symbol (str sym) (str var-sym)) {:ns ns}))))]
      (reduce step {} (js-keys ns-obj)))))

you see that `-` is stored under `_`, e.g. the munged name in the ns-object

cljs.core=> (get (ns-interns** 'cljs.core$macros) '_)
#'cljs.core$macros/_
cljs.core=>


0 votes
by
_Comment made by: mfikes_

Interestingly, the patch works for {{cljs.core/-}} but it doesn't seem to completely work for new symbols defined in {{cljs.user}}, if I'm interpreting this correctly:


cljs.user=> (require 'cljs.js)
true
cljs.user=> (def st (cljs.js/empty-state))
#'cljs.user/st
cljs.user=> (cljs.js/eval st '(def foo-bar 17) {:eval cljs.js/js-eval :context :expr} identity)
{:value 17}
cljs.user=> (cljs.js/eval st 'foo_bar {:eval cljs.js/js-eval :context :expr} identity)
WARNING: Use of undeclared Var cljs.user/foo_bar
{:value 17}
0 votes
by

Comment made by: slipset

Yep

`
cljs.user=> (def foo-bar 17)

'cljs.user/foo-bar

cljs.user=> foo_bar

        ^

WARNING: Use of undeclared Var cljs.user/foo_bar at line 1
17
cljs.user=>
`

Don't remember the details now, but the way I got to fixing the minus was by the code-path which
tries to figure out macros, IIRC.

I guess I'll have to look at the code-path which resolves normal symbols as well.

0 votes
by

Comment made by: mfikes

0001-CLJS-1593-only-return-a-var-when-we-re-looking-for-a.patch fails {{script/test-self-parity}} (x)

In particular, you end up with

WARNING: No such namespace: cljs.inference-util, could not locate cljs/inference_util.cljs, cljs/inference_util.cljc, or JavaScript source providing "cljs.inference-util" (Please check that namespaces with dashes use underscores in the ClojureScript file name) at line 15 src/test/cljs/cljs/inference_test.cljs WARNING: Use of undeclared Var cljs.inference-util/truth_-not-called? at line 15 src/test/cljs/cljs/inference_test.cljs

followed by {{Cannot read property 'truth__not_called_QMARK_' of undefined}} errors, perhaps related to munging of

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJS-1593 (reported by mfikes)
...