ClojureScript

Self-host: Munged minus macro

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Trivial Trivial
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Patch:
    Code

Description

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}

Activity

Hide
Erik Assum added a comment - - edited

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=>
Show
Erik Assum added a comment - - edited 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=>
Hide
Mike Fikes added a comment -

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}
Show
Mike Fikes added a comment - 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}
Hide
Erik Assum added a comment -

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.

Show
Erik Assum added a comment - 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.
Hide
Mike Fikes added a comment -

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

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

Show
Mike Fikes added a comment - 0001-CLJS-1593-only-return-a-var-when-we-re-looking-for-a.patch fails script/test-self-parity 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

People

Vote (1)
Watch (2)

Dates

  • Created:
    Updated: