Fork me on GitHub
#clojurescript
<
2021-06-08
>
Yair Taboch11:06:31

hey all, i have a question about macros in clojure script. why do i need to declare the macros in a clj file first?

borkdude11:06:06

macros are executed in Clojure (unless you are using self-hosted)

quoll12:06:04

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.

quoll12:06:55

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

quoll12:06:10

I need to look now, don’t I? 😊

quoll12:06:55

Yes, it’s written in Clojure 🙂

🤓 6
Yair Taboch14:06:27

it's the same as other compileres. most of the compilers (if not all of them) are written in their language

quoll14:06:50

Clojure is not!

😲 3
Yair Taboch15:06:43

any idea why?

quoll18:06:14

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.

4
sova-soars-the-sora23:06:35

i found this back and forth quite insightful! thank you @U051N6TTC

👍 3
sansarip14:06:14

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

dnolen15:06:05

@yairt there is no ClojureScript runtime - thus the compiler is not available in the execution environment

dnolen15:06:52

the reason for this design is that the web is desirable target - and including the compiler in the runtime is quite heavy

dnolen15:06:10

and simply useless for a very large number of applications

metal 3
👍 3
ange20:06:06

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?

ange21:06:49

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.

sova-soars-the-sora18:06:59

hmmmm. can you access the repl via ssh?

ange15:06:38

Yes, no issues editing files or running repl on the remote machine via ssh session.

Donnie West23:06:35

Does anyone have an example of exporting a default ESM module from a ClojureScript file in any tooling? (shadow-cljs, figwheel, etc)