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.


cljs.user=> (require 'cljs.js)
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
_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)

(in-ns 'cljs.js)
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"}

With a special `ns-interns**` as

(defn ns-interns**
  "Bootstrap only."
  (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) '_)

0 votes
_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)
cljs.user=> (def st (cljs.js/empty-state))
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

Comment made by: slipset


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


cljs.user=> foo_bar


WARNING: Use of undeclared Var cljs.user/foo_bar at line 1

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

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
Reference: https://clojure.atlassian.net/browse/CLJS-1593 (reported by mfikes)