This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-15
Channels
- # announcements (2)
- # babashka (27)
- # beginners (53)
- # boot (3)
- # calva (5)
- # cider (1)
- # clj-kondo (46)
- # cljdoc (38)
- # cljs-dev (40)
- # cljsrn (1)
- # clojars (5)
- # clojure (61)
- # clojure-europe (124)
- # clojure-germany (3)
- # clojure-losangeles (6)
- # clojure-nl (12)
- # clojure-uk (11)
- # clojurescript (44)
- # clojureverse-ops (7)
- # datomic (13)
- # events (3)
- # introduce-yourself (1)
- # jackdaw (5)
- # lsp (115)
- # malli (1)
- # off-topic (16)
- # polylith (2)
- # releases (1)
- # remote-jobs (6)
- # shadow-cljs (10)
- # sql (2)
- # timbre (1)
- # tools-deps (30)
- # vim (34)
- # xtdb (20)
@plexus sorry been really busy w/ work, I've been thinking a bit about the expand to require change - one thing I don't understand now is why parse-ns
needed to be changed
Okay @dnolen, copying from #clojurescript:
;; example/core.clj
(ns example.core)
(defmacro add-three [x]
`(+ ~x 3))
Compiles to:
goog.provide("example.core$macros");
var ret__38016__auto___49 = bob.core$macros.add_three = (function example$core$macros$add_three(_AMPERSAND_form,_AMPERSAND_env,x){
return cljs.core.sequence.call(null,cljs.core.concat.call(null,(new cljs.core.List(null,new cljs.core.Symbol("cljs.core","+","cljs.core/+",(-342754435),null),null,(1),null)),(new cljs.core.List(null,x,null,(1),null)),(new cljs.core.List(null,(3),null,(1),null))));
});
(example.core$macros.add_three.cljs$lang$macro = true);
And
;; example/core.cljs
(ns example.core
:require-macros [example.core :refer [add-three]])
(println (add-three 4))
fails to compile with error:
#error {:message Could not parse ns form example.core in file /example/core.clj, :data {:tag :cljs/analysis-error}, :cause #error {:message Invalid :refer, macro example.core/add-three does not exist in file /example/core.clj, :data {:tag :cljs/analysis-error}}}
Ah, woops, copy/paste problem. Here it is:
(ns example.core
(:require-macros [example.core :refer [add-three]]))
(println (add-three 4))
Switching the extension from clj
to cljc
doesn't seem to do anything. Although that's probably not too surprising since eval-str
expects that I provide my own load-fn, which is:
(defn ns->string [fs {:keys [name macros path]} cb]
((fn rec [extensions]
(if (empty? extensions)
(cb nil)
(let [file-path (str "/" path "." (first extensions))]
(ocall
fs :readFile
file-path
(fn [err data]
(if err
(rec (rest extensions))
(cb {:lang (if (= (first extensions)
"js")
:js
:clj)
:source (.toString data)
:file file-path})))))))
(if macros
["clj" "cljc"]
["cljs" "cljc" "js"])))
Which I think matches the *load-fn*
docs: http://cljs.github.io/api/cljs.js/STARload-fnSTAR
hrm I can't really dig into this right now - but I mean the above should work - and we run all the normal tests against self-hosted
i.e. self-hosted runs the entire standard set of runtime tests - macros have to work etc.
hmm..okay, thanks. By knowing it 'should' work helps. (By removing that particular class of 'user error', and meaning possibly I'm setting up the environment incorrectly. ) Anyway, thanks. 🙂
https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/js.cljs#L1362-L1374
@leif are you trying have macros be in the same file? I do not understand how that relates to your problems above