hey all, i have a question about macros in clojure script. why do i need to declare the macros in a clj file first?
macros are executed in Clojure (unless you are using self-hosted)
Expanding on that… The ClojureScript->JavaScript compiler is a Clojure program. It’s this program that executes the macros that generate ClojureScript output. Once all the macro output has been created, then the combination of the original ClojureScript sources and the macro output can be converted together.
i found this back and forth quite insightful! thank you @quoll
Come to think of it, I just assumed that it was a Clojure program. It runs on the JVM. I guess it could have been written using Java, but I presumed not
I need to look now, don’t I? 😊
Yes, it’s written in Clojure 🙂
And if you are thinking about using macros in a self-hosted way, the source code for Klangmeister really helped me out 🎵 https://github.com/ctford/klangmeister/blob/a9cdae2c3d0b71e458576fb693f5cf4654ba73e9/src/klangmeister/compile/eval.cljs
it's the same as other compileres. most of the compilers (if not all of them) are written in their language
Clojure is not!
any idea why?
@yairt there is no ClojureScript runtime - thus the compiler is not available in the execution environment
the reason for this design is that the web is desirable target - and including the compiler in the runtime is quite heavy
and simply useless for a very large number of applications
Well, Clojure didn’t exist when Rich was writing Clojure 🙂 Rich then https://download.clojure.org/papers/clojure-hopl-iv-final.pdf: > Multimethods are quite flexible, and performance is good enough for many applications, e.g., multimethods are used for Clojure’s polymorphic printing. But they cannot be made as fast as Java method dispatch. Thus the initial release of Clojure lacked a sufficient polymorphic dispatch system to define something like Clojure in Clojure. Once Clojure had elements that allowed for the sort of performance necessary, this happened… insofar as ClojureScript was written in Clojure/ClojureScript. A separate project was created, called “https://github.com/remleduff/CinC”. This was then moved into contrib as tools.analyzer, tools.analyzer.jvm and tools.emitter.jvm. But for now Clojure is still in Java, and there hasn’t been pressure to change that.
Cljs.main question - How to run cljs.main on a remote cloud server, for example a Digital Ocean linux droplet, and connect to browser on local PC?
I was able to get it to work with figwheel.main but not cljs.main. "$ clojure -m figwheel.main" on the remote machine, ssh port forward tunnel for browser connection from PC to remote machine, browser loaded the page and connected to the remote repl. With cljs.main the browser connected but the repl would hang at that point and not get to prompt for input. Thanks.
hmmmm. can you access the repl via ssh?
Yes, no issues editing files or running repl on the remote machine via ssh session.
Does anyone have an example of exporting a default ESM module from a ClojureScript file in any tooling? (shadow-cljs, figwheel, etc)